How to use the sort function from ramda

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

25
26
27
28
29
30
31
32
33
34
  return [...paths, ...nestedPaths]
}

const scopes = R.pipe(
  R.reduce(allPathCombinations, []),
  R.sort((a, b) => a.localeCompare(b)),
  R.uniq,
  R.addIndex(R.map)((name, index) => {
    return {
      value: name,
fork icon11
star icon40
watch icon12

49
50
51
52
53
54
55
56
57
58
59
[
  { name: 'Emma', age: 70 },
  { name: 'Peter', age: 78 },
  { name: 'Mikhail', age: 62 },
];
const peopleByIncreasingAge = R.sort(byAge, people);
//=> [{ name: 'Mikhail', age: 62 },{ name: 'Emma', age: 70 }, { name: 'Peter', age: 78 }]


/*
 * CONCAT
fork icon19
star icon15
watch icon0

+ 5 other calls in file

238
239
240
241
242
243
244
245
246
247
    offer: R.call(R.pipe(R.filter(function (_ref14) {
      var operator = _ref14.operator;
      return operator === Number(id);
    }), (0, _helpers.sortOffersByMinPrice)(query.get(_fn.QUERY_PARAMS.CURRENCY)), R.head), R.concat(offers, getOffersListFromSearchMemory(queryID)))
  };
}), R.sort(R.ascend(R.pathOr(Infinity, ['offer', 'price', query.get(_fn.QUERY_PARAMS.CURRENCY)]))), R.map(function (_ref15) {
  var offer = _ref15.offer,
      entity = _objectWithoutProperties(_ref15, _excluded);

  return R.mergeAll([entity, {
fork icon0
star icon3
watch icon4

+ 41 other calls in file

11
12
13
14
15
16
17
18
19
20
21
22
23
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }


function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }


var sortOffersByMinPrice = function sortOffersByMinPrice(currency) {
  return R.sort(R.ascend(R.path(['price', currency])));
};


exports.sortOffersByMinPrice = sortOffersByMinPrice;
var sortHotelsByMinOffer = R.sort(R.ascend(R.path([0, 'price', 'uah'])));
fork icon0
star icon3
watch icon0

57
58
59
60
61
62
63
64
65
66
67
68


var sortOffers = function sortOffers(offersHub, currency) {
  return function (offers) {
    return R.call(R.pipe(R.map(function (offerID) {
      return offersHub[offerID];
    }), R.sort(R.ascend(R.path(['price', currency])))), offers);
  };
};


var sortPrices = function sortPrices(currency) {
fork icon0
star icon3
watch icon0

4
5
6
7
8
9
10
11
12
13
14


const result = R.pipe(
    // countBy is used to count the frequency by it's identity and returns as object
    R.countBy(R.identity),  // count using its identity[x => x] => {1:3, 2:2, 3:1} 
    R.toPairs,  // =>[[1,3], [2,2], [3,1]]
    R.sort((a, b) => b[1] - a[1]),  // sort using value =>[[1,3], [2,2], [3,1]]
    R.take(k),  // slice array => [[1,3], [2,2]]
    R.map(ele => ele[0]), // return all first elements as array => [1,2]
    R.map(R.unary(parseInt))
);
fork icon0
star icon1
watch icon0

+ 2 other calls in file

69
70
71
72
73
74
75
76
77
78
79
})


const getMonkeyBusiness = R.pipe(
  R.pluck('inspected'),
  R.values,
  R.sort(R.descend(R.identity)),
  R.take(2),
  R.apply(R.multiply),
)

fork icon0
star icon1
watch icon0

96
97
98
99
100
101
102
103
104
105
106
(content)


const part1 = R.compose(
  R.apply(R.multiply),
  R.takeLast(2),
  R.sort(R.subtract),
  R.pluck('inspects'),
  R.reduce(runRound(Infinity), R.__, Array(20))
)(monkeys1)

fork icon0
star icon0
watch icon0

+ 7 other calls in file

1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
 *
 *      var cmp = R.comparator((a, b) => a.age < b.age);
 *      var people = [
 *        // ...
 *      ];
 *      R.sort(cmp, people);
 */
var comparator = _curry1(function comparator(pred) {
    return function (a, b) {
        return pred(a, b) ? -1 : pred(b, a) ? 1 : 0;
fork icon0
star icon0
watch icon0

+ 35 other calls in file

18
19
20
21
22
23
24
25
26
27
28
)(elves);


// part 2
R.pipe(
  R.map(R.sum),
  R.sort((a, b) => (b - a)),
  R.take(3),
  R.sum,
  console.log,
)(elves);
fork icon0
star icon0
watch icon0

-1
fork icon0
star icon0
watch icon0

1016
1017
1018
1019
1020
1021
1022
1023
1024
*      const people = [
*        { name: 'Emma', age: 70 },
*        { name: 'Peter', age: 78 },
*        { name: 'Mikhail', age: 62 },
*      ];
*      const peopleByYoungestFirst = R.sort(byAge, people);
*        //=> [{ name: 'Mikhail', age: 62 },{ name: 'Emma', age: 70 }, { name: 'Peter', age: 78 }]
*/

fork icon0
star icon0
watch icon2

+ 15 other calls in file

65
66
67
68
69
70
71
72
73
74
75
76
  };
};


// descentDraw :: [Coin] -> Number -> [Coin] -> String -> Selection
const descentDraw = (targets, feePerByte, coins, changeAddress) =>
  findTarget(targets, feePerByte, sort(Coin.descentSort, coins), changeAddress);


// ascentDraw :: [Coin] -> Number -> [Coin] -> String -> Selection
const ascentDraw = (targets, feePerByte, coins, changeAddress) =>
  findTarget(targets, feePerByte, sort(Coin.ascentSort, coins), changeAddress);
fork icon0
star icon0
watch icon0

+ 3 other calls in file

245
246
247
248
249
250
251
252
253
254
    }
    reject({error: 'Updates in contact could not be found'})
  })
}

var sortByCreatedDate = R.sort(R.descend(R.prop('create_dt')))

prepareItem(req)
  .then(persistence_lib.findContact)
  .then(findUpdatesIdsInContact)
fork icon0
star icon0
watch icon0

32
33
34
35
36
37
38
39
40
41
vacancies: R.prop('capacity'),
available: () => true,
// get the starting price
pricing: root => {
  // sort ascending
  const sorted = R.sort(R.ascend(R.path(['customer_prototype', 'total_including_tax'])), root.customer_type_rates);
  return sorted[0];
},
unitPricing: root => R.path(['customer_type_rates'], root),
pickupAvailable: root => Boolean(root.lodgings && root.lodgings.some(l => l.is_pickup_available)),
fork icon0
star icon0
watch icon0

249
250
251
252
253
254
255
256
257

  return auth;
})(authors);

if (sort.toLowerCase() === "asc") {
  data = R.sort(R.ascend(R.prop(order)))(data);
} else if (sort.toLowerCase() === "desc") {
  data = R.sort(R.descend(R.prop(order)))(data);
}
fork icon0
star icon0
watch icon0

49
50
51
52
53
54
55
56
57
58
 * @param {string} fileEnv
 */
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

108
109
110
111
112
113
114
115
116
117
118
  }


  console.log(R.compose(
    R.reduce(R.multiply, 1),
    R.take(2),
    R.sort(R.flip(R.subtract)),
    R.pluck('inspectionCount')
  )(monkeyList))
}

fork icon0
star icon0
watch icon0

Other functions in ramda

Sorted by popularity

function icon

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