From 077a72d4758bc8b63f74701e67e69dc9563a65ff Mon Sep 17 00:00:00 2001 From: Immortal Date: Sun, 3 Mar 2024 20:28:21 +0330 Subject: [PATCH] Update randomizeElements.ts --- src/helpers/randomizeElements.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/helpers/randomizeElements.ts b/src/helpers/randomizeElements.ts index 4c249ec..d855fd6 100644 --- a/src/helpers/randomizeElements.ts +++ b/src/helpers/randomizeElements.ts @@ -1,8 +1,7 @@ -export function randomizeElements(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(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; } \ No newline at end of file