# indexed-search

> Find the index of a value in a sorted array heka fast

Latest version **1.1.1** (published 2019-07-07) · ISC license · 0 weekly downloads

## Install

```sh
npm install indexed-search
pnpm add indexed-search
yarn add indexed-search
bun add indexed-search
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.1 |
| Published | 2019-07-07 |
| First published | 2017-12-31 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 6.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | korynunn |

## Links

- npm: https://www.npmjs.com/package/indexed-search
- Repository: https://github.com/KoryNunn/indexed-search
- Homepage: https://github.com/KoryNunn/indexed-search#readme
- Issues: https://github.com/KoryNunn/indexed-search/issues
- npm.io page: https://npm.io/package/indexed-search

## Recent versions

- 1.1.1 (latest) — 2019-07-07
- 1.1.0 — 2018-06-06
- 1.0.0 — 2017-12-31

## README

# indexed-search

Find the index of a value in a sorted array heka fast

This can find an item in an 10M length array in less than 1 millisecond on a modern laptop.

## Usage

indexedSearch(sortedArray, valueToFind[, comparitorFunction (optional), findLowestOrHighest (optional)]);

```javascript

var dataSet = [];

// Produce a set of data between -1 and 1
for(var i = 0; i < 1000000; i++){
    dataSet.push(Math.sin(i));
}

// Ensure the set is sorted
dataSet.sort((a, b) => a - b);

indexedSearch(dataSet, 0); // -> 499999

```

With a custom comparitor function:

```javascript

var dataSet = [];

// Produce a sorted set of strings
for(var i = 0; i < 1000000; i++){
    dataSet.push(i.toString(32));
}

var randomIndex = Math.ceil(Math.random() * dataSet.length) - 1;

indexedSearch(dataSet, 0, (a, b) => a < b ? -1 : 1); // -> randomIndex

```

Force finding higest or lowest index of a value:
`-1` for lowest, `1` for highest

```javascript

var dataSet = [1, 2, 2, 2, 2, 2, 3];

indexedSearch(dataSet, 2); // -> index of the first item found (unspecified between 1 and 5)

indexedSearch(dataSet, 2, -1); // -> 1

indexedSearch(dataSet, 2, 1); // -> 5

```

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