š JavaScript and TypeScript implementation of lower_bound and upper_bound for efficient data searching.
npm install bounditlower_bound and upper_bound for efficient data searching.
bash
npm install boundit
`
Usage
$3
Returns the index of the first element in the array which is greater than or equal to the target.
`typescript
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
`
$3
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.
`typescript
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
`
$3
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.
`typescript
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
``