0.2.0 • Published 9 years ago
cmpby v0.2.0
cmpby

Make comparator from key function or less function.
Comparator is a function that given two arguments a and b returns a number that is:
- negative if
aprecedesb; - zero if
aandbare effectively equal; - positive if
bprecedesa.
Comparators are used in such functions as Array.prototype.sort to set up object ordering.
Example
> ['aaa', 'zz', 'd'].sort(cmpby(a => a.length))
[ 'd', 'zz', 'aaa' ]
> ['aaa', 'zz', 'd'].sort(cmpby.less((a, b) => a.length < b.length ))
[ 'd', 'zz', 'aaa' ]API
cmpby([options], keyfn)
keyfn :: Object -> KeyConstructs comparator from the key function.
cmpby([options], lessfn)
lessfn :: (Object, Object) -> BooleanConstructs comparator from the less-than function.
cmpby([options])
Returns the default comparator.
options.asc
| type | default | description |
|---|---|---|
| Boolean | true | If false, inverts comparator |
Install
npm install cmpbyLicense
MIT
