source: node_modules/ramda-adjunct/es/sortByProp.js

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
Line 
1import { __, append, identity, useWith } from 'ramda';
2import sortByProps from './sortByProps';
3
4/**
5 * Sort a list of objects by a property.
6 *
7 * @func sortByProp
8 * @memberOf RA
9 * @since {@link https://char0n.github.io/ramda-adjunct/3.4.0|v3.4.0}
10 * @category List
11 * @sig k -> [{k: v}] -> [{k: v}]
12 * @param {Array.<string>} prop The property in the list param to sort by
13 * @param {Array.<object>} list A list of objects to be sorted
14 * @return {Array.<object>} A new list sorted by the property in the prop param
15 * @example
16 *
17 * // sorting list of tuples
18 * const sortByFirstItem = sortByProp(0);
19 * const listOfTuples = [[-1, 1], [-2, 2], [-3, 3]];
20 * sortByFirstItem(listOfTuples); // => [[-3, 3], [-2, 2], [-1, 1]]
21 *
22 * // sorting list of objects
23 * const sortByName = sortByProp('name');
24 * const alice = {
25 * name: 'ALICE',
26 * age: 101,
27 * };
28 * const bob = {
29 * name: 'Bob',
30 * age: -10,
31 * };
32 * const clara = {
33 * name: 'clara',
34 * age: 314.159,
35 * };
36 * const people = [clara, bob, alice];
37 * sortByName(people); // => [alice, bob, clara]
38 */
39
40var addValueInAnArray = append(__, []);
41var sortByProp = useWith(sortByProps, [addValueInAnArray, identity]);
42export default sortByProp;
Note: See TracBrowser for help on using the repository browser.