Skip to content

TehShrike/binary-search-range

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

binary-search-range

NPM

Built on binary-search. Returns all indexes of items that match the comparator.

const haystack = [ 1, 3, 5, 6, 6, 6, 9, 11, 14 ]
const needle = 6
const comparator = (a, b) => a - b
binarySearchRange(haystack, needle, comparator) // => [ 3, 4, 5 ]

binarySearchRange(haystack, needle, comparator, lowIndex, highIndex)

comparator should be a function that returns 0 for matches, just like your sort function.

License

WTFPL

About

Use binary search to find a range of matching elements

Resources

Stars

Watchers

Forks

Packages

No packages published