JSPM

@extra-array/bsearch-right

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

Binary searches rightmost value in sorted array.

Package Exports

  • @extra-array/bsearch-right

Readme

Binary searches rightmost value in sorted array. 🏃 📼 📦 🌔 📒

Alternatives: bsearch, bsearchRight, bsearchAny, bsearchClosest.
This is part of package extra-array.

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

var x = [1, 3, 3, 3, 5];
array.bsearchRight(x, 3);
// 3              ^ found rightmost

array.bsearchRight(x, 4);
// -5 (~4)           ^ not found, closest

var x = [1, -3, -3, -3, 5];
array.bsearchRight(x, 3, (a, b) => Math.abs(a) - Math.abs(b));
// 3                 ^

array.bsearchRight(x, 3, null, v => Math.abs(v));
// 3                 ^

references