Socket
Socket
Sign inDemoInstall

@geoffcox/binary-search

Package Overview
Dependencies
0
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @geoffcox/binary-search

A modern binary search algorithm in Typscript.


Version published
Weekly downloads
1
Maintainers
1
Install size
12.9 kB
Created
Weekly downloads
 

Readme

Source

This library contains a binary search algorithm written in Typescript.

Features

  • The search method supports any time of items in the array.
  • The comparison function is injected into the algorithm.
  • When the value is not found, the search provides the nearest range where the value should have been found.

This package ships in ES and CommonJS module formats along with DTS for typing.

Installation and Usage

npm install @geoffcox/binary-search
    const values = [1,2,3,4,5];
    const nearestRange: NearestRange = {};

    const compare = (a: number, b: number) => a-b;
    const result = binarySearch(4, values, compare, nearestRange);

    //expect result to be index of 3 and nearestRange to be [2,4]

Demo

Enjoy it at http://geoffcox.github.io/demos/binary-search

Keywords

FAQs

Last updated on 28 Dec 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc