don't, make a copy of input array, instead shuffle it in PseudoRandom.shuffleArray

This commit is contained in:
evanpelle
2025-05-18 14:04:25 -07:00
parent 9916f21aab
commit 0cd32c807a
+3 -6
View File
@@ -108,14 +108,11 @@ export class PseudoRandom {
* Returns a shuffled copy of the array using Fisher-Yates algorithm.
*/
shuffleArray<T>(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;
}
}