Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@moaoa
Created October 19, 2020 09:06
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 moaoa/ddd2026d1262d0af8b45478a7906484e to your computer and use it in GitHub Desktop.
Save moaoa/ddd2026d1262d0af8b45478a7906484e to your computer and use it in GitHub Desktop.
//One could (or should) use it as a protoype from Array:
//From ChristopheD:
Array.prototype.shuffle = function() {
var i = this.length, j, temp;
if ( i == 0 ) return this;
while ( --i ) {
j = Math.floor( Math.random() * ( i + 1 ) );
temp = this[i];
this[i] = this[j];
this[j] = temp;
}
return this;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment