(array: Array<T>, predicate: (value: T, index: number, obj: T[]) => boolean)
| 7 | * findLastIndex immediately returns that element index. Otherwise, findLastIndex returns -1. |
| 8 | */ |
| 9 | export function findLastIndex<T>(array: Array<T>, predicate: (value: T, index: number, obj: T[]) => boolean): number { |
| 10 | let l = array.length |
| 11 | while (l--) { |
| 12 | if (predicate(array[l], l, array)) { |
| 13 | return l |
| 14 | } |
| 15 | } |
| 16 | return -1 |
| 17 | } |
| 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) |
no outgoing calls
no test coverage detected