# compare-numbers

> Compare two numbers, return -1/0/1. To be used to sort arrays

Latest version **0.0.1** (published 2014-03-31) · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.1 |
| Published | 2014-03-31 |
| First published | 2014-03-31 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Olivier Scherrer |
| Maintainers | podefr |
| Keywords | compare, numbers, sort |

## Links

- npm: https://www.npmjs.com/package/compare-numbers
- Repository: git@github.com:cosmosio/compare-numbers
- Homepage: https://github.com/cosmosio/compare-numbers
- Issues: https://github.com/cosmosio/compare-numbers/issues
- npm.io page: https://npm.io/package/compare-numbers

## Alternatives

- [random-seedable](https://npm.io/package/random-seedable.md) — 27.9K weekly downloads
- [n2words](https://npm.io/package/n2words.md) — 22.2K weekly downloads
- [@stdlib/math-base-special-factorialln](https://npm.io/package/@stdlib/math-base-special-factorialln.md) — 5.7K weekly downloads
- [@stdlib/math-base-special-abs2](https://npm.io/package/@stdlib/math-base-special-abs2.md) — 1.7K weekly downloads
- [commons-math-interpolation](https://npm.io/package/commons-math-interpolation.md) — 1.4K weekly downloads

## Recent versions

- 0.0.1 (latest) — 2014-03-31

## README

Compare numbers
=============

Compare numbers:

With the `asc` function: compare A and B, returns 1 if A is greater, -1 if lower, 0 if both are equal. Can be used with array.sort().
With the `desc` function: compare A and B, returns -1 if A is greater, 1 if lower, 0 if both are equal. Can be used with array.sort().

Installation
============

```bash
npm install compare-numbers
```

How to use
==========

Require compare-numbers:

```js
var compareNumbers = require("compare-numbers");
```

```js
compareNumbers.asc(10, 1); // 1
compareNumbers.asc(1, 10); // -1
compareNumbers.asc(10, 10); // 0
```

```js
compareNumbers.desc(10, 1); // -1
compareNumbers.desc(1, 10); // 1
compareNumbers.desc(10, 10); // 0
```

To be used with array.sort to sort arrays:

```js
[10, 2, 30, 45, 60].sort(compareNumbers.asc); // [2, 10, 30, 45, 60];
```

```js
[10, 2, 30, 45, 60].sort(compareNumbers.desc); // [60, 45, 30, 10, 2];
```

LICENSE
=======

MIT

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