UNPKG

751 BJavaScriptView Raw
1import _curry3 from "./internal/_curry3.js";
2/**
3 * Takes a function and two values, and returns whichever value produces the
4 * larger 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.max, R.minBy
16 * @example
17 *
18 * // square :: Number -> Number
19 * const square = n => n * n;
20 *
21 * R.maxBy(square, -3, 2); //=> -3
22 *
23 * R.reduce(R.maxBy(square), 0, [3, -5, 4, 1, -2]); //=> -5
24 * R.reduce(R.maxBy(square), 0, []); //=> 0
25 */
26
27var maxBy =
28/*#__PURE__*/
29_curry3(function maxBy(f, a, b) {
30 return f(b) > f(a) ? b : a;
31});
32
33export default maxBy;
\No newline at end of file