2016-10-05 19:29:32 -07:00
|
|
|
define(['./_baseClamp', './_copyArray', './_shuffleSelf'], function(baseClamp, copyArray, shuffleSelf) {
|
2016-09-17 22:24:52 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A specialized version of `_.sampleSize` for arrays.
|
|
|
|
|
*
|
|
|
|
|
* @private
|
|
|
|
|
* @param {Array} array The array to sample.
|
|
|
|
|
* @param {number} n The number of elements to sample.
|
|
|
|
|
* @returns {Array} Returns the random elements.
|
|
|
|
|
*/
|
|
|
|
|
function arraySampleSize(array, n) {
|
2016-10-05 19:29:32 -07:00
|
|
|
return shuffleSelf(copyArray(array), baseClamp(n, 0, array.length));
|
2016-09-17 22:24:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return arraySampleSize;
|
|
|
|
|
});
|