findIndexBack
Finds the last
element in an array
that satisfies a predicate
function.
Throws
Error
: If thearray
isempty
.Error
: If no element in thearray
satisfies thepredicate
function.
Type
type findIndexBack = <E>(predicate: ((e: E) => boolean)) => (a: Array<E>) => number
Example
import {findIndexBack} from 'fnxt/array';
function isEven(num: number): boolean {
return num % 2 === 0;
}
const array = [1, 2, 3, 4, 5];
const lastEven = findIndexBack(isEven)(array);
// lastEven is 3