Package Exports
- binary-search-variations
- binary-search-variations/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (binary-search-variations) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
binary-search-variations
Dont want to write lengthly binary search algos in your code? Then this package is for you. binary-search-variations is a npm package which contains all important variations of binary search algorithm, which you can implement in your code with just one line of code.
Read the documentation below to know more about the package.
Installation
npm i binary-search-variations
Usage
const { findGreatestLess } = 'binary-search-variations'
const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9]
const target = 5
const index = findGreatestLess(arr, target)
console.log(index) // 3
The functionalities included in this package - a. Normal Binary Search(normalBinarySearch): This is the normal binary search algorithm which returns the index of the element if found, else returns -1.
b. Find Lower Bound(findLowerBound): This function returns the index of the first element which is greater than or equal to the given element. If no such element is found, it returns -1.
c. Find Upper Bound(findUpperBound): This function returns the index of the first element which is greater than the given element. If no such element is found, it returns -1.
d. Find Least Greater(findLeastGreater): This function returns the index of the least element which is greater than the given element. If no such element is found, it returns -1.
e. Find Greatest Lesser(findGreatestLesser): This function returns the index of the greatest element which is lesser than the given element. If no such element is found, it returns -1.