Slash-The-Hordes/assets/Scripts/Services/Utils/ArrayUtils.ts
2022-11-25 12:00:09 +01:00

11 lines
322 B
TypeScript

export function shuffle<T>(array: T[]): T[] {
const shuffledArray: T[] = [...array];
for (let i = shuffledArray.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[shuffledArray[i], shuffledArray[j]] = [shuffledArray[j], shuffledArray[i]];
}
return shuffledArray;
}