Skip to content

Instantly share code, notes, and snippets.

@geminorum
Created October 3, 2016 06:29
Show Gist options
  • Save geminorum/afcbea170d9b2cc53959138e0c3a0e1f to your computer and use it in GitHub Desktop.
Save geminorum/afcbea170d9b2cc53959138e0c3a0e1f to your computer and use it in GitHub Desktop.
/**
* Shuffles array in place.
* @param {Array} a items The array containing the items.
*/
function shuffle(a) {
var j, x, i;
for (i = a.length; i; i--) {
j = Math.floor(Math.random() * i);
x = a[i - 1];
a[i - 1] = a[j];
a[j] = x;
}
}
var myArray = ['1','2','3','4','5','6','7','8','9'];
shuffle(myArray);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment