JSPM

cmpby

0.2.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 23
  • Score
    100M100P100Q48723F
  • License MIT

Create comparator from key or less function

Package Exports

  • cmpby

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (cmpby) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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

type default description
Boolean true If false, inverts comparator

Install

npm install cmpby

License

MIT