Santi's Bisect Library
- 🚀 Lightweight and fast
- 👴 ES3-compliant*
- 💻 Portable between the browser and Node.js
*Hasn't been tested in an actual ES3 environment. Feel free to open an issue or pull request if you find any non-ES3 thing.
Installation
- Via NPM:
npm install @santi100/bisect-lib
- Via Yarn:
yarn add @santi100/bisect-lib
- Via PNPM:
pnpm install @santi100/bisect-lib
API
function bisect<T = unknown>(array: T[], target: T): number;
Searches for target
through array
with a recursive binary-search algorithm (designed for sorted arrays). Returns the index of the first ocurrence of target
, or -1 if it's not present.
Tests show it doesn't work correctly for unsorted arrays, so you shouldn't pass them to this function:
bisectLib.bisect([5, 7, 3], 3)
Also, keep in mind this library doesn't do deep equality for now. You can file an issue if you want this feature.