9 lines
276 B
TypeScript
9 lines
276 B
TypeScript
export default function randomize<T>(input: T[]): T[] {
|
|
let res: T[] = [];
|
|
input = [...input];
|
|
while (input.length > 0) {
|
|
let randomIndex = Math.floor(Math.random() * input.length);
|
|
res.push(...input.splice(randomIndex, 1));
|
|
}
|
|
return res;
|
|
} |