Skip to content

searchRight

Subhajit Sahu edited this page Jun 16, 2020 · 28 revisions

Searches from right, for a value passing a test. 🏃 📼 📦 🌔 📒

Alternatives: search, searchRight, searchAll.
Similar: search, scan, find.

iterable.searchRight(x, fn);
// x:  an iterable
// fn: test function (v, i, x)
// --> index of value, -1 if not found
const iterable = require('extra-iterable');

var x = [1, 2, 3, 4, 5];
iterable.searchRight(x, v => v % 2 == 0);
// 3              ^

iterable.searchRight(x, v => v % 2 == 1);
// 4                 ^

references

Clone this wiki locally