mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-01 07:47:49 +00:00
Remove the unnecessary branch in _.shuffle()
The non-zero case works properly for 0 as well.
This commit is contained in:
@@ -67,4 +67,8 @@
|
||||
return _.range(1000);
|
||||
});
|
||||
|
||||
JSLitmus.test('_.shuffle()', function() {
|
||||
return _.shuffle(numbers);
|
||||
});
|
||||
|
||||
})();
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user