source:
node_modules/es-toolkit/dist/array/shuffle.mjs
| Last change on this file was a762898, checked in by , 5 months ago | |
|---|---|
|
|
| File size: 267 bytes | |
| Rev | Line | |
|---|---|---|
| [a762898] | 1 | function shuffle(arr) { |
| 2 | const result = arr.slice(); | |
| 3 | for (let i = result.length - 1; i >= 1; i--) { | |
| 4 | const j = Math.floor(Math.random() * (i + 1)); | |
| 5 | [result[i], result[j]] = [result[j], result[i]]; | |
| 6 | } | |
| 7 | return result; | |
| 8 | } | |
| 9 | ||
| 10 | export { shuffle }; |
Note:
See TracBrowser
for help on using the repository browser.
