Skip to content

lastIndexOf

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

Find last index of value using binary search.

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


function lastIndexOf(x, v, i)
// x: a sorted array
// v: search value
// i: begin index [|x|-1]

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

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

xsortedArray.lastIndexOf(x, 40);
// → 4


References

Clone this wiki locally