Skip to content

Commit

Permalink
Update randomizeElements.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
ircfspace committed Mar 3, 2024
1 parent 7b19386 commit 9f3d7b3
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/helpers/randomizeElements.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
export function randomizeElements<T>(arr: T[]) {
let result = [...arr].sort(() => 0.5 - Math.random() );
result = result.slice(0, 100);
result = result.sort(() => 0.5 - Math.random() );
return result;
export function randomizeElements<T>(arr: T[]): T[] {
const result: T[] = [...arr];
for (let i: number = result.length - 1; i > 0; i--) {
const j: number = Math.floor(Math.random() * (i + 1));
[result[i], result[j]] = [result[j], result[i]];
}
return result.slice(0, 100);
}

0 comments on commit 9f3d7b3

Please sign in to comment.