Binary searches rightmost value in sorted array.
npm install @extra-array/bsearchr.minBinary searches rightmost value in [sorted] array.
> Alternatives: [default], [closest], [left], [right].
> This is part of package [extra-array].
[extra-array]: https://www.npmjs.com/package/extra-array
> This is browserified, minified version of [@extra-array/bsearchr].
> It is exported as global variable array_bsearchr.
> CDN: [unpkg], [jsDelivr].
[@extra-array/bsearchr]: https://www.npmjs.com/package/@extra-array/bsearchr
[unpkg]: https://unpkg.com/@extra-array/bsearchr.min
[jsDelivr]: https://cdn.jsdelivr.net/npm/@extra-array/bsearchr.min
``javascript`
array.bsearchr(x, v, [fn]);
// x: an array (sorted)
// v: value to find
// fn: compare function (a, b)
// --> last index of value | ~(index of closest value)
`javascript
const array = require('extra-array');
array.bsearchr([1, 3, 5, 7], 5);
// 2 ^ found
array.bsearchr([1, 3, 5, 7], 4);
// -3 (~2) ^ not found, closest
array.bsearchr([4, 4, 4, 4], 4);
// 3 ^ rightmost
array.bsearchr(['b', 'GB', 'KB', 'MB'], 'kB', (a, b) => {
return a.toLowerCase().localeCompare(b.toLowerCase());
});
// 2 ^ case insensitive
``
- array-binsearch: @krisselden
- binarysearch: @soldair
[sorted]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort
[default]: https://github.com/nodef/extra-array/wiki/bsearch
[closest]: https://github.com/nodef/extra-array/wiki/bsearchc
[left]: https://github.com/nodef/extra-array/wiki/bsearchl
[right]: https://github.com/nodef/extra-array/wiki/bsearchr