Skip to content

Instantly share code, notes, and snippets.

@cuduy197
Forked from rodrigograca31/shuffle-array.js
Created September 15, 2017 19:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cuduy197/0c5e7bd453ae5cc88ef3ca6785355dfd to your computer and use it in GitHub Desktop.
Save cuduy197/0c5e7bd453ae5cc88ef3ca6785355dfd to your computer and use it in GitHub Desktop.
Shuffle Array in Javascript
/**
* Randomize array element order in-place.
* Using Durstenfeld shuffle algorithm.
*/
function shuffleArray(array) {
for (var i = array.length - 1; i > 0; i--) {
var j = Math.floor(Math.random() * (i + 1));
var temp = array[i];
array[i] = array[j];
array[j] = temp;
}
return array;
}
//shuffleArray(questions);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment