You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

17 lines
500 B

4 years ago
  1. var baseClamp = require('./_baseClamp'),
  2. copyArray = require('./_copyArray'),
  3. shuffleSelf = require('./_shuffleSelf');
  4. /**
  5. * A specialized version of `_.sampleSize` for arrays.
  6. *
  7. * @private
  8. * @param {Array} array The array to sample.
  9. * @param {number} n The number of elements to sample.
  10. * @returns {Array} Returns the random elements.
  11. */
  12. function arraySampleSize(array, n) {
  13. return shuffleSelf(copyArray(array), baseClamp(n, 0, array.length));
  14. }
  15. module.exports = arraySampleSize;