Get a compare function for array to sort
Install
$ npm install --save compare-func
Usage
var compareFunc = ; // sort by an object propertyx: 'b' x: 'a' x: 'c';//=> [{x: 'a'}, {x: 'b'}, {x: 'c'}] // sort by a nested object propertyx: y: 'b' x: y: 'a';//=> [{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';//=> [{x: 'b', y: 'a'}, {x: 'b', y: 'b'}, {x: 'c', y: 'c'}] // sort by the returned valuex: 'b' x: 'a' x: 'c';//=> [{x: 'a'}, {x: 'b'}, {x: 'c'}]
API
compareFunc([property])
Returns a compare function for array to sort
property
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.
Related
- sort-on - Sort an array on an object property
License
MIT © Steve Mao