(arrToShuffle: Array<T>)
| 1 | /** Shuffle array using the Fisher–Yates shuffle algorithm */ |
| 2 | export const shuffleArray = <T>(arrToShuffle: Array<T>) => { |
| 3 | const arr = [...arrToShuffle]; |
| 4 | |
| 5 | for (let i = arr.length - 1; i > 0; i--) { |
| 6 | const j = Math.floor(Math.random() * (i + 1)); |
| 7 | |
| 8 | // We know that i and j are within the bounds of the array, TS doesn't |
| 9 | // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion |
| 10 | [arr[i], arr[j]] = [arr[j]!, arr[i]!]; |
| 11 | } |
| 12 | |
| 13 | return arr; |
| 14 | }; |
no outgoing calls
no test coverage detected