compound-sort

0.1.1 • Public • Published

compound-sort

Create a compound sort / comparator function from one or more comparators

Example

function cmpa(a, b) {
  return a.a < b.a ? -1 : (a.a === b.a ? 0 : 1)
}

function cmpb(a, b) {
  return a.b < b.b ? -1 : (a.b === b.b ? 0 : 1)
}

//
// Returns a function that compares first by cmpa, then by cmpb
// for values that tie with respect to cmpa
//
compound(cmpa, cmpb)

Readme

Keywords

none

Package Sidebar

Install

npm i compound-sort

Weekly Downloads

1

Version

0.1.1

License

MIT

Last publish

Collaborators

  • ashaffer88