# array-binarysearch

> Get index of value in sorted array.

Latest version **0.2.9** (published 2019-03-31) · MIT license · 0 weekly downloads

## Install

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

## 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.2.9 |
| Published | 2019-03-31 |
| First published | 2018-01-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 2.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | wolfram77@gmail.com |
| Maintainers | wolfram77 |
| Keywords | array, binary, search |

## Links

- npm: https://www.npmjs.com/package/array-binarysearch
- npm.io page: https://npm.io/package/array-binarysearch

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

- 0.2.9 (latest) — 2019-03-31
- 0.2.8 — 2019-03-31
- 0.2.7 — 2018-09-24
- 0.2.6 — 2018-02-12
- 0.2.5 — 2018-02-11
- 0.2.4 — 2018-02-11
- 0.2.3 — 2018-02-11
- 0.2.2 — 2018-01-28
- 0.2.1 — 2018-01-28
- 0.2.0 — 2018-01-28
- 0.1.6 — 2018-01-20
- 0.1.5 — 2018-01-20
- 0.1.4 — 2018-01-20
- 0.1.3 — 2018-01-20
- 0.1.2 — 2018-01-20
- … 11 more at https://npm.io/package/array-binarysearch/versions

## README

Get index of value in [sorted] [array].
> Use [binarySearch.closest], if index of closest value is needed.<br>
> Use [binarySearch.first], if index of first value is needed.<br>
> Use [binarySearch.last], if index of last value is needed.

```javascript
const binarySearch = require('array-binarysearch');
// binarySearch(<array>, <value>, [compare function], [this], [begin=0], [end])
// -> <index of value> | ~<index of closest value>

binarySearch([21, 42, 91, 91], 42);
// 1
binarySearch([21, 42, 91, 91], 42, null, null, 2);
// -3 (-ve => not found, closest: ~(-3) = 2)
binarySearch([21, 42, 91, 91], 91, null, null, 2, 4);
// 3

binarySearch([21, 42, 91, 91], 42, (a, b) => a===b? 0:(a<b? -1:1));
// 1
binarySearch(['G', 'KG', 'KG', 'MG'], 'g', (a, b, i) => a.toLowerCase().localeCompare(b.toLowerCase()), null, 1);
// -2 (-ve => not found, closest: ~(-2) = 1)
binarySearch(['G', 'KG', 'KG', 'MG'], 'KG', (a, b, i, arr) => a.localeCompare(b), null, 1, 4);
// 2
```
> With [extra-array] try `Array.binarySearch()` instead.
<br>


> References: [array-binsearch], [binarysearch].

[sorted]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort
[array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Indexed_collections
[array-binsearch]: https://www.npmjs.com/package/array-binsearch
[binarysearch]: https://www.npmjs.com/package/binarysearch
[binarySearch.closest]: https://www.npmjs.com/package/@extra-array/binary-search.closest
[binarySearch.first]: https://www.npmjs.com/package/@extra-array/binary-search.first
[binarySearch.last]: https://www.npmjs.com/package/@extra-array/binary-search.last
[extra-array]: https://www.npmjs.com/package/extra-array

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