Merge pull request #539 from fawek/_.shuffle

Remove the unnecessary branch in _.shuffle()
This commit is contained in:
Jeremy Ashkenas
2012-04-03 08:48:37 -07:00
2 changed files with 7 additions and 7 deletions

View File

@@ -67,4 +67,8 @@
return _.range(1000);
});
JSLitmus.test('_.shuffle()', function() {
return _.shuffle(numbers);
});
})();

View File

@@ -250,13 +250,9 @@
_.shuffle = function(obj) {
var shuffled = [], rand;
each(obj, function(value, index, list) {
if (index == 0) {
shuffled[0] = value;
} else {
rand = Math.floor(Math.random() * (index + 1));
shuffled[index] = shuffled[rand];
shuffled[rand] = value;
}
rand = Math.floor(Math.random() * (index + 1));
shuffled[index] = shuffled[rand];
shuffled[rand] = value;
});
return shuffled;
};