Skip to content

includes

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

Check if sorted array has a value using binary search.

Similar: includes, indexOf, [lastIndexOf].


function includes(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.includes(x, 30);
// → false

xsortedArray.includes(x, 40);
// → true


References

Clone this wiki locally