mirror of
https://github.com/MartinKral/Slash-The-Hordes
synced 2024-12-26 11:48:54 +00:00
11 lines
322 B
TypeScript
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;
|
|
}
|