mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-08 18:17:48 +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);
|
return _.range(1000);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
JSLitmus.test('_.shuffle()', function() {
|
||||||
|
return _.shuffle(numbers);
|
||||||
|
});
|
||||||
|
|
||||||
})();
|
})();
|
||||||
@@ -250,13 +250,9 @@
|
|||||||
_.shuffle = function(obj) {
|
_.shuffle = function(obj) {
|
||||||
var shuffled = [], rand;
|
var shuffled = [], rand;
|
||||||
each(obj, function(value, index, list) {
|
each(obj, function(value, index, list) {
|
||||||
if (index == 0) {
|
rand = Math.floor(Math.random() * (index + 1));
|
||||||
shuffled[0] = value;
|
shuffled[index] = shuffled[rand];
|
||||||
} else {
|
shuffled[rand] = value;
|
||||||
rand = Math.floor(Math.random() * (index + 1));
|
|
||||||
shuffled[index] = shuffled[rand];
|
|
||||||
shuffled[rand] = value;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
return shuffled;
|
return shuffled;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user