binary-search-party
Asynchronous or Synchronous binary search. This can be useful for seraching through really useless databases like a pipermail archive. If you essentially just have a key value store and a list of keys that are known to be in order, you can efficiently search for a specific value using this module.
Installation
npm install binary-search-party
API
Synchronous
var search = var haystack = 1 2 3 4 5var needle = 4 var index =
Asynchronous
var search = var haystack = 1 2 3 4 5var needle = 4
Promised
var search = var haystack = 1 2 3 4 5var needle = 4
N.B. You will get back the type of promise returned by calling the comparison function. This makes it easy to use your own promise library :)
N.B. If you pass an empty array, the comparison function can never be called so the result will be the literal number -1
. If the array might be empty and you rely on the result being a promise you should assimilate the result into being a promise using something like Promise.from(search(arr, comparison))
License
MIT