mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-03 08:37:49 +00:00
Bump to v4.16.0.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
define(['./_baseClamp', './_baseRandom', './_isIterateeCall', './toArray', './toInteger'], function(baseClamp, baseRandom, isIterateeCall, toArray, toInteger) {
|
||||
define(['./_arraySampleSize', './isArrayLike', './_isIterateeCall', './toInteger', './values'], function(arraySampleSize, isArrayLike, isIterateeCall, toInteger, values) {
|
||||
|
||||
/** Used as a safe reference for `undefined` in pre-ES5 environments. */
|
||||
var undefined;
|
||||
@@ -24,25 +24,12 @@ define(['./_baseClamp', './_baseRandom', './_isIterateeCall', './toArray', './to
|
||||
* // => [2, 3, 1]
|
||||
*/
|
||||
function sampleSize(collection, n, guard) {
|
||||
var index = -1,
|
||||
result = toArray(collection),
|
||||
length = result.length,
|
||||
lastIndex = length - 1;
|
||||
|
||||
if ((guard ? isIterateeCall(collection, n, guard) : n === undefined)) {
|
||||
n = 1;
|
||||
} else {
|
||||
n = baseClamp(toInteger(n), 0, length);
|
||||
n = toInteger(n);
|
||||
}
|
||||
while (++index < n) {
|
||||
var rand = baseRandom(index, lastIndex),
|
||||
value = result[rand];
|
||||
|
||||
result[rand] = result[index];
|
||||
result[index] = value;
|
||||
}
|
||||
result.length = n;
|
||||
return result;
|
||||
return arraySampleSize(isArrayLike(collection) ? collection : values(collection), n);
|
||||
}
|
||||
|
||||
return sampleSize;
|
||||
|
||||
Reference in New Issue
Block a user