0.0.3 • Published 6 months ago

boundit v0.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

Boundit

npm version npm downloads License

šŸ” JavaScript and TypeScript implementation of lower_bound and upper_bound for efficient data searching.

Installation

You can install the package using npm:

npm install boundit

Usage

lowerBound

Returns the index of the first element in the array which is greater than or equal to the target.

import { lowerBound } from "boundit"

const array = [1, 2, 4, 4, 5, 6]
const target = 4
const index = lowerBound(array, target)

console.log(index) // Output: 2

upperBound

Returns the index of the first element in the array which is greater than the target, or the length of the array if no such element is found.

import { upperBound } from "boundit"

const array = [1, 2, 4, 4, 5, 6]
const target = 4
const index = upperBound(array, target)

console.log(index) // Output: 4

binarySearch

Binary search is a fast search algorithm with run-time complexity of O(log n). This search algorithm works on the principle of divide and conquer. For this algorithm to work properly, the data collection should be in the sorted form.

import { binarySearch } from "boundit"

const array = [1, 2, 4, 4, 5, 6]
const target = 5
const index = binarySearch(array, target)

console.log(index) // Output: 4

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

Contributions are welcome! Please open an issue or submit a pull request for any changes.

Author

Vusal Huseynov

Links

0.0.3

6 months ago

0.0.2

6 months ago

0.0.1

6 months ago