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.2 KB
|
Rev | Line | |
---|
[d24f17c] | 1 | var _curry2 =
|
---|
| 2 | /*#__PURE__*/
|
---|
| 3 | require("./internal/_curry2.js");
|
---|
| 4 | /**
|
---|
| 5 | * Sorts a list according to a list of comparators.
|
---|
| 6 | *
|
---|
| 7 | * @func
|
---|
| 8 | * @memberOf R
|
---|
| 9 | * @since v0.23.0
|
---|
| 10 | * @category Relation
|
---|
| 11 | * @sig [(a, a) -> Number] -> [a] -> [a]
|
---|
| 12 | * @param {Array} functions A list of comparator functions.
|
---|
| 13 | * @param {Array} list The list to sort.
|
---|
| 14 | * @return {Array} A new list sorted according to the comarator functions.
|
---|
| 15 | * @see R.ascend, R.descend
|
---|
| 16 | * @example
|
---|
| 17 | *
|
---|
| 18 | * const alice = {
|
---|
| 19 | * name: 'alice',
|
---|
| 20 | * age: 40
|
---|
| 21 | * };
|
---|
| 22 | * const bob = {
|
---|
| 23 | * name: 'bob',
|
---|
| 24 | * age: 30
|
---|
| 25 | * };
|
---|
| 26 | * const clara = {
|
---|
| 27 | * name: 'clara',
|
---|
| 28 | * age: 40
|
---|
| 29 | * };
|
---|
| 30 | * const people = [clara, bob, alice];
|
---|
| 31 | * const ageNameSort = R.sortWith([
|
---|
| 32 | * R.descend(R.prop('age')),
|
---|
| 33 | * R.ascend(R.prop('name'))
|
---|
| 34 | * ]);
|
---|
| 35 | * ageNameSort(people); //=> [alice, clara, bob]
|
---|
| 36 | */
|
---|
| 37 |
|
---|
| 38 |
|
---|
| 39 | var sortWith =
|
---|
| 40 | /*#__PURE__*/
|
---|
| 41 | _curry2(function sortWith(fns, list) {
|
---|
| 42 | return Array.prototype.slice.call(list, 0).sort(function (a, b) {
|
---|
| 43 | var result = 0;
|
---|
| 44 | var i = 0;
|
---|
| 45 |
|
---|
| 46 | while (result === 0 && i < fns.length) {
|
---|
| 47 | result = fns[i](a, b);
|
---|
| 48 | i += 1;
|
---|
| 49 | }
|
---|
| 50 |
|
---|
| 51 | return result;
|
---|
| 52 | });
|
---|
| 53 | });
|
---|
| 54 |
|
---|
| 55 | module.exports = sortWith; |
---|
Note:
See
TracBrowser
for help on using the repository browser.