Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Array shuffle method using Mike Bostock's Fisher-Yates Shuffle implementation. Original is here: http://bost.ocks.org/mike/shuffle/

View array.shuffle.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
/**
* Extends the primitive Array with a random sort function
*
* @returns {Array}
*/
;Array.prototype.shuffle = function() {
 
var arr = this,
m = arr.length,
t,
i;
 
// While there remain elements to shuffle…
while ( m ) {
 
// Pick a remaining element…
i = Math.floor( Math.random() * m-- );
 
// And swap it with the current element.
t = arr[ m ];
arr[ m ] = arr[ i ];
arr[ i ] = t;
}
 
return arr;
 
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.