npm.io
2.10.19 • Published 4 years ago

@extra-array/search

Licence
MIT
Version
2.10.19
Deps
0
Size
4 kB
Vulns
0
Weekly
0
Stars
17

Finds index of first value passing a test.

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

This is part of package extra-array.


array.search(x, ft);
// x:  an array
// ft: test function (v, i, x)
// → index of value, -1 if not found
const array = require("extra-array");

var x = [1, 2, 3, 2, 5];
array.search(x, 2);
// 1        ^

var x = [1, -2, 3, 2, 5];
array.search(x, 2, (a, b) => Math.abs(a) - Math.abs(b));
// 1         ^

var x = [1, -2, 3, 2, 5];
array.search(x, 2, null, v => Math.abs(v));
// 1         ^


References

Keywords