Shuffle array element - Node.js Array

Node.js examples for Array:Shuffle

Description

Shuffle array element

Demo Code


(function(){/*from ww w .j av a2s  . c o  m*/
  Array.prototype.shuffle = function(){
    for (i = 0; i<this.length/2; i++){
      var j = Math.floor(Math.random()*this.length);
      var temp = this[i];
      this[i] = this[j];
      this[j] = temp;
    }
    return this;
  }
})();

Related Tutorials