๐ JavaScript and TypeScript implementation of lower_bound and upper_bound for efficient data searching.
You can install the package using npm:
npm install bounditReturns 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: 2Returns 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: 4Binary 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: 4This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please open an issue or submit a pull request for any changes.
Vusal Huseynov