source: node_modules/ramda/es/descend.js

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: 1.1 KB
Line 
1import _curry3 from "./internal/_curry3.js";
2/**
3 * Makes a descending comparator function out of a function that returns a value
4 * that can be compared with `<` and `>`.
5 *
6 * @func
7 * @memberOf R
8 * @since v0.23.0
9 * @category Function
10 * @sig Ord b => (a -> b) -> a -> a -> Number
11 * @param {Function} fn A function of arity one that returns a value that can be compared
12 * @param {*} a The first item to be compared.
13 * @param {*} b The second item to be compared.
14 * @return {Number} `-1` if fn(a) > fn(b), `1` if fn(b) > fn(a), otherwise `0`
15 * @see R.ascend
16 * @example
17 *
18 * const byAge = R.descend(R.prop('age'));
19 * const people = [
20 * { name: 'Emma', age: 70 },
21 * { name: 'Peter', age: 78 },
22 * { name: 'Mikhail', age: 62 },
23 * ];
24 * const peopleByOldestFirst = R.sort(byAge, people);
25 * //=> [{ name: 'Peter', age: 78 }, { name: 'Emma', age: 70 }, { name: 'Mikhail', age: 62 }]
26 */
27
28var descend =
29/*#__PURE__*/
30_curry3(function descend(fn, a, b) {
31 var aa = fn(a);
32 var bb = fn(b);
33 return aa > bb ? -1 : aa < bb ? 1 : 0;
34});
35
36export default descend;
Note: See TracBrowser for help on using the repository browser.