Home › Forums › JavaScript › [1,2,3,4,5,6,7,8,9].shuffle() › Re: [1,2,3,4,5,6,7,8,9].shuffle()
July 21, 2013 at 7:30 am
#143864
Kuzyo
Participant
It’s nice solution **shuffleArr.splice(pos, 0, elem);** I didn’t know how to make that elem go to different position, because Math.random() can repeat themselves, thats why there was this strange
if ( shuffleArr[pos] == undefined)
but, why you use:
pos = Math.floor( Math.random() * (shuffleArr.length + 1) )
this works too:
pos = Math.floor( Math.random() * len );
Thanks @CrocoDillon for your help