continue-custom/core/util/findLast.ts
2024-12-12 17:17:15 -08:00

14 lines
258 B
TypeScript

export function findLastIndex(
arr: any[],
criterion: (item: any) => boolean,
): number {
let lastIndex = -1;
for (let i = arr.length - 1; i >= 0; i--) {
if (criterion(arr[i])) {
lastIndex = i;
break;
}
}
return lastIndex;
}