Randomize order of options
This commit is contained in:
9
src/rand.ts
Normal file
9
src/rand.ts
Normal file
@ -0,0 +1,9 @@
|
||||
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;
|
||||
}
|
Reference in New Issue
Block a user