Original array but with the order "shuffled" - Node.js Array

Node.js examples for Array:Shuffle

Description

Original array but with the order "shuffled"

Demo Code

/**//from  w ww. ja v  a  2 s. c om
 *
 * http://jsfromhell.com/array/shuffle
 * http://www.brain4.de/programmierecke/js/arrayShuffle.php
 *
 * @return {Array} original array but with the order "shuffled"
 *
 */
Array.prototype.shuffle = function() {
    for (var j, x, i=this.length; i; j=parseInt(Math.random() * i), x=this[--i], this[i]=this[j], this[j]=x);
};

Related Tutorials