This project is archived and is in readonly mode.

#184 ✓resolved
zeekaak

new function: Array.shuffle()

Reported by zeekaak | November 13th, 2009 @ 01:33 PM | in backlog (closed)

I was missing a function in the Array class: 'shuffle()'. With this function you can put all array elements in a random order.
The function could be implemented like this (as found on http://davidwalsh.name/array-shuffling-mootools):

Array.implement({ 
  shuffle: function() { 
    //destination array 
    for(var j, x, i = this.length; i; j = parseInt(Math.random() * i), x = this[--i], this[i] = this[j], this[j] = x); 
    return this; 
  } 
});

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

The MooTools Extensions

People watching this ticket

Pages