Package Exports
- @extra-array/bsearchl.min
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@extra-array/bsearchl.min) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Binary searches leftmost value in sorted array.
Alternatives: default, closest, left, right.
This is part of package extra-array.
This is browserified, minified version of @extra-array/bsearchl.
It is exported as global variable array_bsearchl.
CDN: unpkg, jsDelivr.
array.bsearchl(x, v, [fn]);
// x: an array (sorted)
// v: value to find
// fn: compare function (a, b)
// --> first index of value | ~(index of closest value)
const array = require('extra-array');
array.bsearchl([1, 3, 5, 7], 5);
// 2 ^ found
array.bsearchl([1, 3, 5, 7], 4);
// -3 (~2) ^ not found, closest
array.bsearchl([4, 4, 4, 4], 4);
// 0 ^ leftmost
array.bsearchl(['b', 'GB', 'KB', 'MB'], 'kB', (a, b) => {
return a.toLowerCase().localeCompare(b.toLowerCase());
});
// 2 ^ case insensitive