# compare-function

> Effortlessly compose compare functions for Array.prototype.sort

Latest version **2.0.0** (published 2017-12-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install compare-function
pnpm add compare-function
yarn add compare-function
bun add compare-function
```

## Health

**Score 23/100 (F)** — status: abandoned.

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2017-12-16 |
| First published | 2016-05-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/compare-function) |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Michael Rhodes |
| Maintainers | michaelrhodes |
| Keywords | array, sort, compare, compose |

## Links

- npm: https://www.npmjs.com/package/compare-function
- Repository: https://github.com/michaelrhodes/compare-function
- Issues: https://github.com/michaelrhodes/compare-function/issues
- npm.io page: https://npm.io/package/compare-function

## Recent versions

- 2.0.0 (latest) — 2017-12-16
- 1.0.0 — 2016-05-10

## README

# compare-function

Effortlessly compose compare functions for `Array.prototype.sort`. You provide a value accessor function, it handles the `a < b ? -1 : a > b ? 1 : 0` dance.

[![Build status](https://travis-ci.org/michaelrhodes/compare-function.svg?branch=master)](https://travis-ci.org/michaelrhodes/compare-function)

## Install
```sh
$ npm install compare-function
```

### Example
``` js
var compare = require('compare-function')

var songs = [{
  artist: 'Joy Division',
  track: 'Warsaw'
},{
  artist: 'New Order',
  track: 'Blue Monday'
},{
  artist: 'Freebass',
  track: 'Plan B'
}]

function artist (song) {
  return song.artist
}

songs.sort(compare(artist)).map(artist)
> ['Freebass', 'Joy Division', 'New Order']

songs.sort(compare(-1, artist)).map(artist)
> ['New Order', 'Joy Division', 'Freebass']
```

### See also
- [multi-compare](https://github.com/parshap/js-multi-compare)

### License
[MIT](http://opensource.org/licenses/MIT)

---
_Source: https://npm.io/package/compare-function · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
