ethers.js/packages/providers/src.ts/shuffle.ts
2022-04-11 17:09:17 -04:00

10 lines
254 B
TypeScript

export function shuffle<T = any>(array: Array<T>): void {
for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
const tmp = array[i];
array[i] = array[j];
array[j] = tmp;
}
}