Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript [1,2,3,4,5,6,7,8,9].shuffle() Re: [1,2,3,4,5,6,7,8,9].shuffle()

#143797
Kuzyo
Participant

before sleep was that

Array.prototype.shuffle = function() { 
  var len = this.length; 
  for ( var i = 0; i < len; i++ ) { 
    var ele = this*, pos = this[Math.floor(Math.random()*len)]; 
    if(pos == undefined) { 
      pos = ele; 
    } 
  } 
  return this; 
};