@namhong2001/binary-search
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

very simple binary search

type definition

/**
 * @param low inclusive, must be true on predicate function
 * @param high exclusive,
 * @param predicate predicate function
 */
declare const bsearch: (
  low: number,
  high: number,
  predicate: (mid: number) => boolean
) => number;

Install

npm install @namhong2001/binary-search

example

bsearch(0, 10, (mid) => mid < 5); // 4
bsearch(0, 10, (mid) => mid < 50); // 9, because high(10) is exclusive
bsearch(0, 10, (mid) => mid < -50); // 0, return low(0) even if low is falsy on predicate

LICENSE

MIT

Package Sidebar

Install

npm i @namhong2001/binary-search

Weekly Downloads

45

Version

1.0.1

License

MIT

Unpacked Size

3.8 kB

Total Files

7

Last publish

Collaborators

  • namhong2001