mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-07 01:57:50 +00:00
Bump to v3.9.2.
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
var baseRandom = require('../internal/baseRandom'),
|
||||
toIterable = require('../internal/toIterable');
|
||||
var sample = require('./sample');
|
||||
|
||||
/** Used as references for `-Infinity` and `Infinity`. */
|
||||
var POSITIVE_INFINITY = Number.POSITIVE_INFINITY;
|
||||
|
||||
/**
|
||||
* Creates an array of shuffled values, using a version of the
|
||||
@@ -16,20 +18,7 @@ var baseRandom = require('../internal/baseRandom'),
|
||||
* // => [4, 1, 3, 2]
|
||||
*/
|
||||
function shuffle(collection) {
|
||||
collection = toIterable(collection);
|
||||
|
||||
var index = -1,
|
||||
length = collection.length,
|
||||
result = Array(length);
|
||||
|
||||
while (++index < length) {
|
||||
var rand = baseRandom(0, index);
|
||||
if (index != rand) {
|
||||
result[index] = result[rand];
|
||||
}
|
||||
result[rand] = collection[index];
|
||||
}
|
||||
return result;
|
||||
return sample(collection, POSITIVE_INFINITY);
|
||||
}
|
||||
|
||||
module.exports = shuffle;
|
||||
|
||||
Reference in New Issue
Block a user