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.

32 lines
771 B

4 years ago
  1. import _curry3 from "./internal/_curry3.js";
  2. /**
  3. * Takes a function and two values, and returns whichever value produces the
  4. * smaller result when passed to the provided function.
  5. *
  6. * @func
  7. * @memberOf R
  8. * @since v0.8.0
  9. * @category Relation
  10. * @sig Ord b => (a -> b) -> a -> a -> a
  11. * @param {Function} f
  12. * @param {*} a
  13. * @param {*} b
  14. * @return {*}
  15. * @see R.min, R.maxBy
  16. * @example
  17. *
  18. * // square :: Number -> Number
  19. * const square = n => n * n;
  20. *
  21. * R.minBy(square, -3, 2); //=> 2
  22. *
  23. * R.reduce(R.minBy(square), Infinity, [3, -5, 4, 1, -2]); //=> 1
  24. * R.reduce(R.minBy(square), Infinity, []); //=> Infinity
  25. */
  26. var minBy =
  27. /*#__PURE__*/
  28. _curry3(function minBy(f, a, b) {
  29. return f(b) < f(a) ? b : a;
  30. });
  31. export default minBy;