JSPM

@extra-array/bsearch-right

2.3.26
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 9
  • Score
    100M100P100Q69365F
  • License MIT

Binary searches rightmost value in sorted array.

Package Exports

  • @extra-array/bsearch-right

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/bsearch-right) 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 rightmost value in sorted array.

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

array.bsearchRight(x, v, [fn]);
// x:  an array (sorted)
// v:  search value
// fn: compare function (a, b)
// --> last index of value | ~(index of closest value)
const array = require('extra-array');

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

array.bsearchRight([1, 3, 5, 7], 4);
// -3 (~2)                ^ not found, closest

array.bsearchRight([4, 4, 4, 4], 4);
// 3                         ^ rightmost

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

references