Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@geoffcox/binary-search

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@geoffcox/binary-search

A modern binary search algorithm in Typscript.

  • 1.0.0
  • latest
  • npm
  • Socket score

Version published
Maintainers
1
Created
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

Package last updated on 28 Dec 2022

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc