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 c978a7d commit 077a72d
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/helpers/randomizeElements.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
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);
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() );
result = result.sort(() => 0.5 - Math.random() );
return result;
}

0 comments on commit 077a72d

Please sign in to comment.