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
|
Rev | Line | |
---|
[d24f17c] | 1 | var _curry3 =
|
---|
| 2 | /*#__PURE__*/
|
---|
| 3 | require("./internal/_curry3.js");
|
---|
| 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 |
|
---|
| 31 | var 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 |
|
---|
| 39 | module.exports = ascend; |
---|
Note:
See
TracBrowser
for help on using the repository browser.