Socket
Book a DemoInstallSign in
Socket

cmpby

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cmpby

Create comparator from key or less function

latest
Source
npmnpm
Version
0.2.0
Version published
Maintainers
1
Created
Source

cmpby Build Status Dependency Status

npm

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 a precedes b;
  • zero if a and b are effectively equal;
  • positive if b precedes a.

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 -> Key

Constructs comparator from the key function.

cmpby([options], lessfn)

lessfn :: (Object, Object) -> Boolean

Constructs comparator from the less-than function.

cmpby([options])

Returns the default comparator.

options.asc

typedefaultdescription
BooleantrueIf false, inverts comparator

Install

npm install cmpby

License

MIT

Keywords

comparator

FAQs

Package last updated on 11 Nov 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts