Skip to content

searchValueAny

Subhajit Sahu edited this page Jun 19, 2020 · 1 revision

Find any index of a value using binary search.

Alternatives: [searchValue], [searchValueRight], searchValueAny, [searchClosestValue].


function searchValueAny(x, v, fc, fm)
// x:  a sorted array
// v:  search value
// fc: compare function (a, b)
// fm: map function (v, i, x)

const xsortedArray = require('extra-sorted-array');

var x = [10, 20, 20, 40, 40, 80];
xsortedArray.searchValueAny(x, 30);
// → -4  (~3, where 3 is closest index)

xsortedArray.searchValueAny(x, 40);
// → 3  (or 4)


References

Clone this wiki locally