How to use the comparator function from ramda

Find comprehensive JavaScript ramda.comparator code examples handpicked from public code repositorys.

42
43
44
45
46
47
48
49
50
51
52
 *
 *    @return
 *      returns boolean based on comparision done.
 */


const byAge = R.comparator((a, b) => a.age < b.age);
const people =
[
  { name: 'Emma', age: 70 },
  { name: 'Peter', age: 78 },
fork icon19
star icon15
watch icon0

+ 5 other calls in file

1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
* @sig (a, b -> Boolean) -> (a, b -> Number)
* @param {Function} pred A predicate function of arity two.
* @return {Function} A Function :: a -> b -> Int that returns `-1` if a < b, `1` if b < a, otherwise `0`.
* @example
*
*      var cmp = R.comparator((a, b) => a.age < b.age);
*      var people = [
*        // ...
*      ];
*      R.sort(cmp, people);
fork icon0
star icon0
watch icon0

+ 17 other calls in file

1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
* @param {Function} pred A predicate function of arity two which will return `true` if the first argument
* is less than the second, `false` otherwise
* @return {Function} A Function :: a -> b -> Int that returns `-1` if a < b, `1` if b < a, otherwise `0`
* @example
*
*      const byAge = R.comparator((a, b) => a.age < b.age);
*      const people = [
*        { name: 'Emma', age: 70 },
*        { name: 'Peter', age: 78 },
*        { name: 'Mikhail', age: 62 },
fork icon0
star icon0
watch icon2

+ 3 other calls in file

50
51
52
53
54
55
56
57
58
59
 */
const fileEnvToKey = (fileEnv) =>
  R.filter(
    (key) => !!key,
    R.sort(
      R.comparator((a, b) => a < b),
      R.map(getKeys, getLines(fileEnv))
    )
  );

fork icon0
star icon0
watch icon0

5
6
7
8
9
10
11
12
13
14
15
16
17


const transformSupervisors = (supervisors) => {
  // remove supervisors with numerical jurisdictions
  const filteredNumericalJurisdictions = R.filter(isStringInteger, supervisors);


  const jurisdictionComp = R.comparator((a, b) => a.jurisdiction < b.jurisdiction);
  const lastNameComp = R.comparator((a, b) => a.lastName < b.lastName);
  const firstNameComp = R.comparator((a, b) => a.firstName < b.firstName);


  // sort the filtered list by jurisdiction, last name, and first name
fork icon0
star icon0
watch icon0

+ 5 other calls in file

Other functions in ramda

Sorted by popularity

function icon

ramda.clone is the most popular function in ramda (30311 examples)