Skip to content

scanWhileRight

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

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

Alternatives: search, searchRight, searchAll.

iterable.scanWhileRight(x, fn);
// x:  an iterable
// fn: test function (v, i, x)
// --> first index where test passes 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