# array-binsearch

> Binary search a sorted array

Latest version **1.0.1** (published 2016-11-15) · Apache-2.0 license · 0 weekly downloads

## Install

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

## Health

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

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2016-11-15 |
| First published | 2016-08-31 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Kris Selden |
| Maintainers | krisselden |
| Keywords | array, binary, search |

## Links

- npm: https://www.npmjs.com/package/array-binsearch
- Repository: https://github.com/krisselden/array-binsearch
- Homepage: https://github.com/krisselden/array-binsearch#readme
- Issues: https://github.com/krisselden/array-binsearch/issues
- npm.io page: https://npm.io/package/array-binsearch

## 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

- 1.0.1 (latest) — 2016-11-15
- 1.0.0 — 2016-08-31

## README

# array-binsearch

A library for performing a binary search on an array with insertion support.

Supports typescript usage and rollup.

## Example

### Basic

```
var binsearch = require("./index").default;
var sortedSet = [2, 4, 6, 8, 9, 11];

function add(set, val) {
  var i = binsearch(set, val);
  if (i < 0) {
    i = ~i;
    set.splice(i, 0, val);
  }
}

add(sortedSet, 4);
add(sortedSet, 3);
add(sortedSet, 8);
add(sortedSet, 20);
add(sortedSet, -1);

console.log(sortedSet);

// => [ -1, 2, 3, 4, 6, 8, 9, 11, 20 ]

```

### With Comparator

```
var binsearch = require("./index").default;
var sortedSet = [2, 4, 6, 8, 9, 11];
function comparator(a, b) {
  return a - b;
}

function add(set, val) {
  var i = binsearch(set, val);
  if (i < 0) {
    i = ~i;
    set.splice(i, 0, val);
  }
}

add(sortedSet, 4);
add(sortedSet, 3);
add(sortedSet, 8);
add(sortedSet, 20);
add(sortedSet, -1);

console.log(sortedSet);

// => [ -1, 2, 3, 4, 6, 8, 9, 11, 20 ]

```

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