package
Get a compare function for array to sort
npm install compare-funcGitHub-flavored package documentation.
Across all versions, last 30 days.
62,950,494 in 30 days
Runtime metadata.
Tagged topics.
Get a compare function for array to sort
$ npm install --save compare-funcvar compareFunc = require('compare-func');
// sort by an object property
[{x: 'b'}, {x: 'a'}, {x: 'c'}].sort(compareFunc('x'));
//=> [{x: 'a'}, {x: 'b'}, {x: 'c'}]
// sort by a nested object property
[{x: {y: 'b'}}, {x: {y: 'a'}}].sort(compareFunc('x.y'));
//=> [{x: {y: 'a'}}, {x: {y: 'b'}}]
// sort by the `x` propery, then `y`
[{x: 'c', y: 'c'}, {x: 'b', y: 'a'}, {x: 'b', y: 'b'}].sort(compareFunc(['x', 'y']));
Returns a compare function for array to sort
Type: string, function or array of either
If missing it sorts on itself.
The string can be a dot path to a nested object property.
MIT © Steve Mao
Estimated unpacked size across 5 packages.
607.0 kB
Includes dependencies.
^1.0.0
1.0.0