mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-12 20:07:49 +00:00
Move baseClamp use to arraySampleSize and baseSampleSize.
This commit is contained in:
@@ -2433,7 +2433,7 @@
|
|||||||
* @returns {Array} Returns the random elements.
|
* @returns {Array} Returns the random elements.
|
||||||
*/
|
*/
|
||||||
function arraySampleSize(array, n) {
|
function arraySampleSize(array, n) {
|
||||||
return shuffleSelf(copyArray(array), n);
|
return shuffleSelf(copyArray(array), baseClamp(n, 0, array.length));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -3940,7 +3940,8 @@
|
|||||||
* @returns {Array} Returns the random elements.
|
* @returns {Array} Returns the random elements.
|
||||||
*/
|
*/
|
||||||
function baseSampleSize(collection, n) {
|
function baseSampleSize(collection, n) {
|
||||||
return shuffleSelf(values(collection), n);
|
var array = values(collection);
|
||||||
|
return shuffleSelf(array, baseClamp(n, 0, array.length));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -6612,7 +6613,7 @@
|
|||||||
length = array.length,
|
length = array.length,
|
||||||
lastIndex = length - 1;
|
lastIndex = length - 1;
|
||||||
|
|
||||||
size = size === undefined ? length : baseClamp(size, 0, length);
|
size = size === undefined ? length : size;
|
||||||
while (++index < size) {
|
while (++index < size) {
|
||||||
var rand = baseRandom(index, lastIndex),
|
var rand = baseRandom(index, lastIndex),
|
||||||
value = array[rand];
|
value = array[rand];
|
||||||
|
|||||||
Reference in New Issue
Block a user