-
Notifications
You must be signed in to change notification settings - Fork 1
search
wolfram77 edited this page Mar 27, 2020
·
28 revisions
Searches a value from left.
array.search(x, v, [fn]);
// x: an array
// v: search value
// fn: compare function (a, b)
// --> 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 ^