Skip to content

scanUntilRight

Subhajit Sahu edited this page Jun 15, 2020 · 12 revisions

Scans until a test passes, from right. 🏃 📼 📦 🌔 📒

Alternatives: [scanWhile], [scanWhileRight], [scanUntil], [scanUntilRight].
Similar: search, [scan], [find].

iterable.scanUntilRight(x, fn);
// x:  an iterable
// fn: test function (v, i, x)
// --> first index where test fails till end
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               ^

iterable.searchRight(x, 2, null, v => Math.abs(v));
// 3               ^

references

Clone this wiki locally