_baseExtremum.js 897 B

123456789101112131415161718192021222324252627282930313233
  1. var isSymbol = require('./isSymbol');
  2. /**
  3. * The base implementation of methods like `_.max` and `_.min` which accepts a
  4. * `comparator` to determine the extremum value.
  5. *
  6. * @private
  7. * @param {Array} array The array to iterate over.
  8. * @param {Function} iteratee The iteratee invoked per iteration.
  9. * @param {Function} comparator The comparator used to compare values.
  10. * @returns {*} Returns the extremum value.
  11. */
  12. function baseExtremum(array, iteratee, comparator) {
  13. var index = -1,
  14. length = array.length;
  15. while (++index < length) {
  16. var value = array[index],
  17. current = iteratee(value);
  18. if (current != null && (computed === undefined
  19. ? (current === current && !isSymbol(current))
  20. : comparator(current, computed)
  21. )) {
  22. var computed = current,
  23. result = value;
  24. }
  25. }
  26. return result;
  27. }
  28. module.exports = baseExtremum;