mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 14:50:44 +00:00
don't, make a copy of input array, instead shuffle it in PseudoRandom.shuffleArray
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user