12 lines
359 B
TypeScript
12 lines
359 B
TypeScript
export const arrayOfLength = (length: number): number[] => {
|
|
return [...Array(length).keys()]
|
|
}
|
|
|
|
export function arrayShuffle(array: any[]) {
|
|
const copy = [...array]; // Create a shallow copy
|
|
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;
|
|
}
|