Socket
Socket
Sign inDemoInstall

binary-search-bounds

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

binary-search-bounds

Better binary searching


Version published
Weekly downloads
217K
decreased by-20.26%
Maintainers
1
Weekly downloads
 
Created

What is binary-search-bounds?

The binary-search-bounds npm package provides utilities for performing binary search operations on sorted arrays. It allows you to find the insertion points for elements, as well as the lower and upper bounds for elements in a sorted array.

What are binary-search-bounds's main functionalities?

binarySearch

This feature allows you to perform a binary search to find the exact index of an element in a sorted array. In this example, the element 3 is found at index 2.

const bsb = require('binary-search-bounds');
const arr = [1, 2, 3, 4, 5];
const index = bsb.eq(arr, 3); // 2
console.log(index);

lowerBound

This feature allows you to find the lower bound (first occurrence) of an element in a sorted array. In this example, the first occurrence of the element 2 is at index 1.

const bsb = require('binary-search-bounds');
const arr = [1, 2, 2, 2, 3, 4, 5];
const index = bsb.ge(arr, 2); // 1
console.log(index);

upperBound

This feature allows you to find the upper bound (first element greater than the given element) in a sorted array. In this example, the first element greater than 2 is at index 4.

const bsb = require('binary-search-bounds');
const arr = [1, 2, 2, 2, 3, 4, 5];
const index = bsb.gt(arr, 2); // 4
console.log(index);

insertionPoint

This feature allows you to find the insertion point for an element in a sorted array. In this example, the insertion point for the element 3 is at index 2.

const bsb = require('binary-search-bounds');
const arr = [1, 2, 3, 4, 5];
const index = bsb.le(arr, 3); // 2
console.log(index);

Other packages similar to binary-search-bounds

Keywords

FAQs

Package last updated on 25 Jan 2021

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