-
Notifications
You must be signed in to change notification settings - Fork 5
search
Subhajit Sahu edited this page May 3, 2023
·
23 revisions
Find index of first value passing a test.
Alternatives: search, searchRight, searchAll.
Similar: search, scan, find.
function search(x, ft)
// x: an array
// ft: test function (v, i, x)
const xarray = require('extra-array');
var x = [1, 2, 3, 2, 5];
xarray.search(x, 2);
// → 1 ^
var x = [1, -2, 3, 2, 5];
xarray.search(x, 2, (a, b) => Math.abs(a) - Math.abs(b));
// → 1 ^
var x = [1, -2, 3, 2, 5];
xarray.search(x, 2, null, v => Math.abs(v));
// → 1 ^