_arraySample.js 363B

12345678910111213141516
  1. var baseRandom = require('./_baseRandom');
  2. /**
  3. * A specialized version of `_.sample` for arrays.
  4. *
  5. * @private
  6. * @param {Array} array The array to sample.
  7. * @returns {*} Returns the random element.
  8. */
  9. function arraySample(array) {
  10. var length = array.length;
  11. return length ? array[baseRandom(0, length - 1)] : undefined;
  12. }
  13. module.exports = arraySample;