Randomize order of options

This commit is contained in:
Fabian Stamm
2019-09-11 18:36:31 +02:00
parent f091b318d4
commit 82aed19f85
3 changed files with 15 additions and 3 deletions

9
src/rand.ts Normal file
View 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;
}