Random order

This commit is contained in:
Manav Rathi
2024-05-04 18:48:43 +05:30
parent ee503b3bce
commit 575e4809d8
2 changed files with 73 additions and 4 deletions

View File

@@ -8,8 +8,8 @@
* then we sort by this key. Since the key is random, the sorted array will have
* the original elements in a random order.
*/
export const shuffle = <T>(xs: T[]) =>
export const shuffled = <T>(xs: T[]) =>
xs
.map((x) => [Math.random(), x])
.sort()
.map(([, x]) => x);
.map(([, x]) => x) as T[];