Skip to content

Commit

Permalink
tweak _.shuffle
Browse files Browse the repository at this point in the history
  • Loading branch information
clottes committed Feb 8, 2013
1 parent 7615764 commit adc778a
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions underscore.js
Expand Up @@ -740,12 +740,10 @@ var till = _.till = _.until = function(obj, iterator, context, pass) {


// Shuffle an array. // Shuffle an array.
_.shuffle = function(obj) { _.shuffle = function(obj) {
var rand; var shuffled = [], rand;
var index = 0; each(obj, function(value,index) {
var shuffled = []; rand = Math.floor(Math.random() * (index + 1));
each(obj, function(value) { shuffled[index] = shuffled[rand];
rand = _.random(index++);
shuffled[index - 1] = shuffled[rand];
shuffled[rand] = value; shuffled[rand] = value;
}); });
return shuffled; return shuffled;
Expand Down

0 comments on commit adc778a

Please sign in to comment.