Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/can-dy-jack/js-binary-search

JavaScript binary search implementation.
https://github.com/can-dy-jack/js-binary-search

Last synced: about 1 month ago
JSON representation

JavaScript binary search implementation.

Awesome Lists containing this project

README

        

# binary search ![npm version](https://img.shields.io/npm/v/@kartjim/js-binary-search?style=flat-square) [![Node.js CI](https://github.com/can-dy-jack/js-binary-search/actions/workflows/test.yml/badge.svg?branch=master)](https://github.com/can-dy-jack/js-binary-search/actions/workflows/test.yml)

JavaScript binary search implementation.

> 仿 `Python` `bisect`二分函数模块;

## install
```sh
npm i @kartjim/js-binary-search
```

## import
```js
const {
bisect_left,
bisect_right
} = require('@kartjim/js-binary-search');
```

or use CDN:
```js

```

## use
```js
bisect_left([1, 2, 4, 5], 3) // 2
bisect_left([1, 2, 3, 4, 5], 3) // 2

bisect_right([1, 2, 4, 5], 3) // 2
bisect_right([1, 2, 3, 4, 5], 3) // 3
```

## API
```ts
export type bisect_left = (
arr: [],
val: number,
left: number = 0,
right: number = arr.length
) => number;
export type bisect_right = (
arr: [],
val: number,
left: number = 0,
right: number = arr.length
) => number;
```