Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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.
- Host: GitHub
- URL: https://github.com/can-dy-jack/js-binary-search
- Owner: can-dy-jack
- License: mit
- Created: 2023-02-15T05:01:55.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2023-02-15T08:42:15.000Z (almost 2 years ago)
- Last Synced: 2024-11-02T04:42:09.770Z (3 months ago)
- Language: JavaScript
- Size: 68.4 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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) // 2bisect_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;
```