# sorted-array

> An implementation of John von Neumann's sorted arrays in JavaScript. Implements insertion sort and binary search for fast insertion and deletion.

Latest version **2.0.4** (published 2019-03-01) · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install sorted-array
pnpm add sorted-array
yarn add sorted-array
bun add sorted-array
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 2.0.4 |
| Published | 2019-03-01 |
| First published | 2013-05-01 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 8.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 69 |
| Author | Aadit M Shah |
| Maintainers | aaditmshah |
| Keywords | sorted, array, Neumann, insertion, sort, insert, binary, search, deletion, delete |

## Links

- npm: https://www.npmjs.com/package/sorted-array
- Repository: https://github.com/aaditmshah/sorted-array
- Issues: https://github.com/aaditmshah/sorted-array/issues
- npm.io page: https://npm.io/package/sorted-array

## Alternatives

- [jsforce](https://npm.io/package/jsforce.md) — 851.2K weekly downloads
- [react-native-qrcode-svg](https://npm.io/package/react-native-qrcode-svg.md) — 693.5K weekly downloads
- [@salesforce/plugin-data](https://npm.io/package/@salesforce/plugin-data.md) — 394.9K weekly downloads
- [@backstage/plugin-search-common](https://npm.io/package/@backstage/plugin-search-common.md) — 308.5K weekly downloads
- [@chain-registry/types](https://npm.io/package/@chain-registry/types.md) — 38.4K weekly downloads

## Recent versions

- 2.0.4 (latest) — 2019-03-01
- 2.0.3 — 2019-03-01
- 2.0.2 — 2018-01-17
- 2.0.1 — 2015-01-17
- 2.0.0 — 2015-01-16
- 1.1.1 — 2014-03-28
- 1.1.0 — 2013-05-01
- 1.0.0 — 2013-05-01

## README

# Sorted Array #

An implementation of John von Neumann's sorted arrays in JavaScript. Implements insertion sort and binary search for fast insertion and deletion.

## Installation ##

Sorted arrays may be installed on [node.js](http://nodejs.org/ "node.js") via the [node package manager](https://npmjs.org/ "npm") using the command `npm install sorted-array`.

You may also install it on [RingoJS](http://ringojs.org/ "Home - RingoJS") using the command `ringo-admin install javascript/sorted-array`.

You may install it as a [component](https://github.com/component/component "component/component") for web apps using the command `component install javascript/sorted-array`.

## Usage ##

The six line tutorial on sorted arrays:

```javascript
var SortedArray = require("sorted-array");
var sorted = new SortedArray([3, 1, 5, 2, 4]);
console.dir(sorted.array);                     // [1, 2, 3, 4, 5]
sorted.search(3);                              // 2
sorted.remove(3);                              // [1, 2, 4, 5]
sorted.insert(3);                              // [1, 2, 3, 4, 5]
```

You may pass an optional [compare function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort) as a second argument to the `SortedArray` constructor.

You may also use the `SortedArray.comparing(property, array)` factory function to create a new `SortedArray` which compares values by their `property`. For example, to compare arrays by `length`:

```javascript
var SortedArray = require("sorted-array");
var sorted = SortedArray.comparing(length, [[3,3,3], [1], [5,5,5,5,5], [2,2], [4,4,4,4]]);
console.dir(sorted.array);              // [[1], [2,2], [3,3,3], [4,4,4,4], [5,5,5,5,5]]

function length(a) {
    return a.length;
}
```

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