main
Last change
on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago |
Initial commit
|
-
Property mode
set to
100644
|
File size:
840 bytes
|
Rev | Line | |
---|
[d24f17c] | 1 | import _curry3 from "./internal/_curry3.js";
|
---|
| 2 | import min from "./min.js";
|
---|
| 3 | /**
|
---|
| 4 | * Takes a function and two values, and returns whichever value produces the
|
---|
| 5 | * smaller result when passed to the provided function.
|
---|
| 6 | *
|
---|
| 7 | * @func
|
---|
| 8 | * @memberOf R
|
---|
| 9 | * @since v0.8.0
|
---|
| 10 | * @category Relation
|
---|
| 11 | * @sig Ord b => (a -> b) -> a -> a -> a
|
---|
| 12 | * @param {Function} f
|
---|
| 13 | * @param {*} a
|
---|
| 14 | * @param {*} b
|
---|
| 15 | * @return {*}
|
---|
| 16 | * @see R.min, R.maxBy
|
---|
| 17 | * @example
|
---|
| 18 | *
|
---|
| 19 | * // square :: Number -> Number
|
---|
| 20 | * const square = n => n * n;
|
---|
| 21 | *
|
---|
| 22 | * R.minBy(square, -3, 2); //=> 2
|
---|
| 23 | *
|
---|
| 24 | * R.reduce(R.minBy(square), Infinity, [3, -5, 4, 1, -2]); //=> 1
|
---|
| 25 | * R.reduce(R.minBy(square), Infinity, []); //=> Infinity
|
---|
| 26 | */
|
---|
| 27 |
|
---|
| 28 | var minBy =
|
---|
| 29 | /*#__PURE__*/
|
---|
| 30 | _curry3(function minBy(f, a, b) {
|
---|
| 31 | var resultB = f(b);
|
---|
| 32 | return min(f(a), resultB) === resultB ? b : a;
|
---|
| 33 | });
|
---|
| 34 |
|
---|
| 35 | export default minBy; |
---|
Note:
See
TracBrowser
for help on using the repository browser.