mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-01 23:57:49 +00:00
Optimize _.shuffle.
This commit is contained in:
@@ -5242,13 +5242,16 @@
|
||||
function shuffle(collection) {
|
||||
collection = toIterable(collection);
|
||||
|
||||
var index = -1,
|
||||
var index = 0,
|
||||
length = collection.length,
|
||||
result = Array(length);
|
||||
|
||||
if (length) {
|
||||
result[index] = collection[index];
|
||||
}
|
||||
while (++index < length) {
|
||||
var value = collection[index],
|
||||
rand = baseRandom(0, index);
|
||||
rand = baseRandom(0, index - 1);
|
||||
|
||||
result[index] = result[rand];
|
||||
result[rand] = value;
|
||||
|
||||
Reference in New Issue
Block a user