Skip to content

indexOf

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

Find first index of value using binary search.

Similar: [includes], indexOf, [lastIndexOf].


function indexOf(x, v, i)
// x: a sorted array
// v: search value
// i: begin index [0]

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

var x = [10, 20, 20, 40, 40, 80];
xsortedArray.indexOf(x, 30);
// → -1

xsortedArray.indexOf(x, 40);
// → 3


References

Clone this wiki locally