/
outbreak
/
kilocode
Обзор
Документация
Войти
/
outbreak
/
kilocode
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/shared/array.ts
22 строки
873 B
Saoud Rizwan
Initial streaming refactor
09 окт 2024, 08:49
09 окт 2024, 08:49
1cc3546
Код
Авторство
О чём код?
/** * Returns the index of the last element in the array where predicate is true, and -1 * otherwise. * @param array The source array to search in * @param predicate find calls predicate once for each element of the array, in descending * order, until it finds one where predicate returns true. If such an element is found, * findLastIndex immediately returns that element index. Otherwise, findLastIndex returns -1. */ export function findLastIndex<T>(array: Array<T>, predicate: (value: T, index: number, obj: T[]) => boolean): number { let l = array.length while (l--) { if (predicate(array[l], l, array)) { return l } } return -1 } export function findLast<T>(array: Array<T>, predicate: (value: T, index: number, obj: T[]) => boolean): T | undefined { const index = findLastIndex(array, predicate) return index === -1 ? undefined : array[index] }