Skip to content

Instantly share code, notes, and snippets.

@LukeberryPi
Created November 26, 2023 18:41
Show Gist options
  • Save LukeberryPi/3009c1765e13f4c110d6c178e552c9aa to your computer and use it in GitHub Desktop.
Save LukeberryPi/3009c1765e13f4c110d6c178e552c9aa to your computer and use it in GitHub Desktop.
fisher-yates/knuth shuffle in javascript
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