ethers.js/packages/random/src.ts/shuffle.ts
2019-11-01 23:33:51 +09:00

15 lines
315 B
TypeScript

"use strict";
export function shuffled(array: Array<any>): Array<any> {
array = array.slice();
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;
}
return array;
}