monk-import-export
Version:
Simple import & export sorting ESLint plugin
11 lines (9 loc) • 407 B
text/typescript
// Like `Array.prototype.findIndex`, but searches from the end.
export function findLastIndex<T>(array: T[], fn: (item: T, index: number, arr: T[]) => void[]): number {
for (let index = array.length - 1; index >= 0; index--) {
if (fn(array[index], index, array)) return index;
}
// There are currently no usages of `findLastIndex` where nothing is found.
// istanbul ignore next
return -1;
}