Created
November 26, 2023 18:41
-
-
Save LukeberryPi/3009c1765e13f4c110d6c178e552c9aa to your computer and use it in GitHub Desktop.
fisher-yates/knuth shuffle in javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function shuffle(arr) { | |
for (let i = 0; i < arr.length - 1; i++) { | |
const j = Math.floor(Math.random() * (i + 1)); | |
[arr[i], arr[j]] = [arr[j], arr[i]]; | |
} | |
return arr; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment