From 0cd32c807a7cf7bc61e44637ae84f74bac67f8fb Mon Sep 17 00:00:00 2001 From: evanpelle Date: Sun, 18 May 2025 14:04:25 -0700 Subject: [PATCH] don't, make a copy of input array, instead shuffle it in PseudoRandom.shuffleArray --- src/core/PseudoRandom.ts | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/core/PseudoRandom.ts b/src/core/PseudoRandom.ts index 39ef87ab0..daf27497f 100644 --- a/src/core/PseudoRandom.ts +++ b/src/core/PseudoRandom.ts @@ -108,14 +108,11 @@ export class PseudoRandom { * Returns a shuffled copy of the array using Fisher-Yates algorithm. */ shuffleArray(array: T[]): T[] { - // Create a copy to avoid modifying the original array - const arrayCopy = [...array]; - - for (let i = arrayCopy.length - 1; i >= 0; i--) { + for (let i = array.length - 1; i >= 0; i--) { const j = this.nextInt(0, i + 1); - [arrayCopy[i], arrayCopy[j]] = [arrayCopy[j], arrayCopy[i]]; + [array[i], array[j]] = [array[j], array[i]]; } - return arrayCopy; + return array; } }