Javascript Array shuffle(deep)

Description

Javascript Array shuffle(deep)


Array.prototype.shuffle = function(deep) {
 var i = this.length,
  j, t;/* w w  w. j a  v  a2 s  . c o  m*/
 while (i) {
  j = Math.floor((i--) * Math.random());
  t = deep && typeof this[i].shuffle !== 'undefined' ? this[i].shuffle() : this[i];
  this[i] = this[j];
  this[j] = t;
 }
 return this;
};



PreviousNext

Related