Skip to content

Commit 0ca60dd

Browse files
committed
fix: bring back findLast
1 parent b397eff commit 0ca60dd

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/shared/array.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,8 @@ export function findLastIndex<T>(array: Array<T>, predicate: (value: T, index: n
1515
}
1616
return -1
1717
}
18+
19+
export function findLast<T>(array: Array<T>, predicate: (value: T, index: number, obj: T[]) => boolean): T | undefined {
20+
const index = findLastIndex(array, predicate)
21+
return index === -1 ? undefined : array[index]
22+
}

0 commit comments

Comments
 (0)