Skip to content

searchRight

Subhajit Sahu edited this page May 10, 2020 · 28 revisions

Searches a value from right. 🏃 📼 📦 🌔

Alternatives: left, right, all.

iterable.searchRight(x, v, [fn]);
// x:  an iterable
// v:  search value
// fn: compare function (a, b)
// --> index of value, -1 if not found
const iterable = require('extra-iterable');

var x = [1, 2, 3, 2, 5];
iterable.searchRight(x, 2);
// 3              ^

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

references

Clone this wiki locally