min.js 614 B

123456789101112131415161718192021222324252627282930
  1. var baseExtremum = require('./_baseExtremum'),
  2. baseLt = require('./_baseLt'),
  3. identity = require('./identity');
  4. /**
  5. * Computes the minimum value of `array`. If `array` is empty or falsey,
  6. * `undefined` is returned.
  7. *
  8. * @static
  9. * @since 0.1.0
  10. * @memberOf _
  11. * @category Math
  12. * @param {Array} array The array to iterate over.
  13. * @returns {*} Returns the minimum value.
  14. * @example
  15. *
  16. * _.min([4, 2, 8, 6]);
  17. * // => 2
  18. *
  19. * _.min([]);
  20. * // => undefined
  21. */
  22. function min(array) {
  23. return (array && array.length)
  24. ? baseExtremum(array, identity, baseLt)
  25. : undefined;
  26. }
  27. module.exports = min;