8 lines
241 B
TypeScript
8 lines
241 B
TypeScript
export function shuffleArray<T>(array: T[]) {
|
|
const copy = Array.from(array)
|
|
for (let i = copy.length - 1; i > 0; i--) {
|
|
const j = Math.floor(Math.random() * (i + 1));
|
|
[copy[i], copy[j]] = [copy[j], copy[i]];
|
|
}
|
|
return copy
|
|
}
|