Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

binsearch

kgryte40.0.0

Perform a bin search over a 1d edge vector

binning, histogram, search, binary search

readme

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.