Skip to content

Instantly share code, notes, and snippets.

@SCG82
Forked from nikolas/array-shuffle.js
Created January 25, 2019 12:03
Show Gist options
  • Save SCG82/e4f8440541fb1ecddbb3fd184475ddfe to your computer and use it in GitHub Desktop.
Save SCG82/e4f8440541fb1ecddbb3fd184475ddfe to your computer and use it in GitHub Desktop.
const shuffleArray = function(array) {
const a = array.slice();
for (let i = a.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[a[i], a[j]] = [a[j], a[i]];
}
return a;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment