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

binsearch

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

binsearch

Perform a bin search over a 1d edge vector

  • 0.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Binsearch

Perform a 1d bin search where bins are defined by an input edge vector.

Examples

var binsearch = require( 'binsearch' ),
	edges, numEdges = 11,
	idx;

// Create a 1d edge array...
edges = new Array( numEdges );

// Note: numBins = numEdges-1
for ( var i = 0; i < numEdges; i++ ) {
	edges[ i ] = i-0.5;
}

// Perform a bin search...
idx = binsearch( edges, 0 );
// returns idx = 0

idx = binsearch( edges, 1 );
// returns idx = 1

idx = binsearch( edges, 5.2345 );
// returns idx = 5

idx = binsearch( edges, 5.5001 );
// returns idx = 6

idx = binsearch( edges, -5 );
// returns idx = -1

idx = binsearch( edges, 100 );
// returns idx = 10

Tests

Unit tests use the Mocha test framework with Chai assertions.

Assuming you have installed Mocha, execute the following command in the top-level application directory to run the tests:

$ mocha

All new feature development should have corresponding unit tests to validate correct functionality.

License

MIT license.


Copyright © 2014. Athan Reines.

Keywords

FAQs

Package last updated on 23 Jun 2014

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