@extra-array/bsearchc.min

2.1.75 • Public • Published

Binary searches closest value in sorted array.

Alternatives: default, closest, left, right.
This is part of package extra-array.

This is browserified, minified version of @extra-array/bsearchc.
It is exported as global variable array_bsearchc.
CDN: unpkg, jsDelivr.

array.bsearchc(x, v, [fn]);
// x:  an array (sorted)
// v:  value to find
// fn: compare function (a, b)
// --> index of closest value
const array = require('extra-array');

array.bsearchc([1, 3, 5, 7], 5);
// 2                  ^ found

array.bsearchc([1, 3, 5, 7], 4);
// 2                  ^ closest

array.bsearchc([4, 4, 4, 4], 4);
// 2                  ^ not left/right most

array.bsearchc(['b', 'GB', 'KB', 'MB'], 'kB', (a, b) => {
  return a.toLowerCase().localeCompare(b.toLowerCase());
});
// 2                        ^ case insensitive

references

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 2.1.75
    1
    • latest

Version History

Package Sidebar

Install

npm i @extra-array/bsearchc.min

Weekly Downloads

1

Version

2.1.75

License

MIT

Unpacked Size

3.93 kB

Total Files

4

Last publish

Collaborators

  • wolfram77