PraxaLing / lib /utils /shuffle.ts
Reubencf's picture
refactor: split practice + phrases clients, share JSON repair
54dbbac
Raw
History Blame Contribute Delete
312 Bytes
// Fisher–Yates shuffle. Returns a new array; doesn't mutate the input.
export function shuffle<T>(input: readonly T[]): T[] {
const out = [...input];
for (let i = out.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[out[i], out[j]] = [out[j], out[i]];
}
return out;
}