ramda-adjunct
Version:
Ramda Adjunct is the most popular and most comprehensive set of utilities for use with Ramda, providing a variety of useful, well tested functions with excellent documentation.
46 lines (44 loc) • 1.45 kB
JavaScript
exports.__esModule = true;
exports["default"] = void 0;
var _ramda = require("ramda");
var _sortByProps = _interopRequireDefault(require("./sortByProps.js"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
/**
* Sort a list of objects by a property.
*
* @func sortByProp
* @memberOf RA
* @since {@link https://char0n.github.io/ramda-adjunct/3.4.0|v3.4.0}
* @category List
* @sig k -> [{k: v}] -> [{k: v}]
* @param {Array.<string>} prop The property in the list param to sort by
* @param {Array.<object>} list A list of objects to be sorted
* @return {Array.<object>} A new list sorted by the property in the prop param
* @example
*
* // sorting list of tuples
* const sortByFirstItem = sortByProp(0);
* const listOfTuples = [[-1, 1], [-2, 2], [-3, 3]];
* sortByFirstItem(listOfTuples); // => [[-3, 3], [-2, 2], [-1, 1]]
*
* // sorting list of objects
* const sortByName = sortByProp('name');
* const alice = {
* name: 'ALICE',
* age: 101,
* };
* const bob = {
* name: 'Bob',
* age: -10,
* };
* const clara = {
* name: 'clara',
* age: 314.159,
* };
* const people = [clara, bob, alice];
* sortByName(people); // => [alice, bob, clara]
*/
var addValueInAnArray = (0, _ramda.append)(_ramda.__, []);
var sortByProp = (0, _ramda.useWith)(_sortByProps["default"], [addValueInAnArray, _ramda.identity]);
var _default = exports["default"] = sortByProp;
;