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