# @writetome51/order-numerically

> Function takes an array of numbers and returns new array with numbers in numeric order

Latest version **1.0.0** (published 2020-08-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install @writetome51/order-numerically
pnpm add @writetome51/order-numerically
yarn add @writetome51/order-numerically
bun add @writetome51/order-numerically
```

## Health

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

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2020-08-23 |
| First published | 2020-08-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 3.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Steve Thompson |
| Maintainers | writetome51 |
| Keywords | numbers, array, fast, sort, sorting, ascending, order, numeric, function |

## Links

- npm: https://www.npmjs.com/package/@writetome51/order-numerically
- Repository: https://github.com/writetome51/order-numerically
- Homepage: https://github.com/writetome51/order-numerically#readme
- Issues: https://github.com/writetome51/order-numerically/issues
- npm.io page: https://npm.io/package/@writetome51/order-numerically

## Dependencies (1)

- [timsort](https://npm.io/package/timsort.md) ^0.3.0

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2020-08-23

## README

# orderNumerically(<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;arr: any[]<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;getValueToSortBy? = (element) => element<br>): void

Re-orders `arr` in ascending numeric order. Uses super-fast [node-timsort](https://github.com/mziccard/node-timsort) for the actual sorting.  
It sorts using this comparison function: `(a, b) => getValueToSortBy(a) - getValueToSortBy(b)`.  
Optional callback `getValueToSortBy(element)` must return a number. By default it simply  
returns the passed `element`.  


## Examples
```js
// A basic number sort:
let numbers = [10, 6, 44, 2, 21, 66, 32, 44];  
orderNumerically(numbers); 
console.log(numbers); 
//  [ 2, 6, 10, 21, 32, 44, 44, 66 ]

// sort objects by property 'age'
let objects = [{age: 12}, {age: 7}, {age: 18}, {age: 5}]; 
orderNumerically(objects, (obj) => obj.age);  
console.log(objects); 
//  [ {age: 5}, {age: 7}, {age: 12}, {age: 18} ]

// sort arrays by length:
let arrays = [ [1,2,3], [1], [], [4,5], [0], [6,7], [4,5,6] ];
orderNumerically(arrays, (arr) => arr.length); 
console.log(arrays);  
// [ [], [1], [0], [4,5], [6,7], [1,2,3], [4,5,6] ]
```

## Installation
`npm i @writetome51/order-numerically`

## Loading
```js
import {orderNumerically} from '@writetome51/order-numerically'; 
```

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