-
Notifications
You must be signed in to change notification settings - Fork 1
scanWhileRight
Subhajit Sahu edited this page Jun 15, 2020
·
12 revisions
Scans while a test passes, from right. 🏃 📼 📦 🌔 📒
Alternatives: [scanWhile], [scanWhileRight], [scanUntil], [scanUntilRight].
Similar: search, [scan], [find].
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 ^