@extra-array/search-right.min

Finds index of last value passing a test. :package: :smiley_cat: :running: :vhs: :moon: :scroll: :newspaper: :blue_book:

Usage no npm install needed!

<script type="module">
  import extraArraySearchRightMin from 'https://cdn.skypack.dev/@extra-array/search-right.min';
</script>

README

Finds index of last value passing a test. :package: :smiley_cat: :running: :vhs: :moon: :scroll: :newspaper: :blue_book:

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

This is part of package extra-array.

This is browserified, minified version of @extra-array/search-right.
It is exported as global variable array_searchRight.
CDN: unpkg, jsDelivr.


array.searchRight(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.searchRight(x, 2);
// 3              ^

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

array.searchRight(x, 2, null, v => Math.abs(v));
// 3               ^


References