UNPKG

1.13 kBJavaScriptView Raw
1var _curry3 =
2/*#__PURE__*/
3require("./internal/_curry3");
4/**
5 * Makes an ascending comparator function out of a function that returns a value
6 * that can be compared with `<` and `>`.
7 *
8 * @func
9 * @memberOf R
10 * @since v0.23.0
11 * @category Function
12 * @sig Ord b => (a -> b) -> a -> a -> Number
13 * @param {Function} fn A function of arity one that returns a value that can be compared
14 * @param {*} a The first item to be compared.
15 * @param {*} b The second item to be compared.
16 * @return {Number} `-1` if fn(a) < fn(b), `1` if fn(b) < fn(a), otherwise `0`
17 * @see R.descend
18 * @example
19 *
20 * const byAge = R.ascend(R.prop('age'));
21 * const people = [
22 * { name: 'Emma', age: 70 },
23 * { name: 'Peter', age: 78 },
24 * { name: 'Mikhail', age: 62 },
25 * ];
26 * const peopleByYoungestFirst = R.sort(byAge, people);
27 * //=> [{ name: 'Mikhail', age: 62 },{ name: 'Emma', age: 70 }, { name: 'Peter', age: 78 }]
28 */
29
30
31var ascend =
32/*#__PURE__*/
33_curry3(function ascend(fn, a, b) {
34 var aa = fn(a);
35 var bb = fn(b);
36 return aa < bb ? -1 : aa > bb ? 1 : 0;
37});
38
39module.exports = ascend;
\No newline at end of file