Yields elements from array that match a given predicate, and moreover are between
the given startIndex (inclusive) and endIndex (exclusive).
While this can be done with in the in-built array.filter function, it will
needlessly iterate through the whole array. It also avoids another alternative
of slicing the array before using filter.
// Return 'registered' people between and including array indexes 5-10 constfiltered = [...filterBetween(people, person=>person.registered, 5, 10)];
Yields elements from
array
that match a givenpredicate
, and moreover are between the givenstartIndex
(inclusive) andendIndex
(exclusive).While this can be done with in the in-built
array.filter
function, it will needlessly iterate through the whole array. It also avoids another alternative of slicing the array before usingfilter
.