shared package (#22626)
This commit is contained in:
parent
af20191d1c
commit
be9432a893
144 changed files with 246 additions and 242 deletions
10
packages/shared/src/util/array.ts
Normal file
10
packages/shared/src/util/array.ts
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
export function findLast<T>(
|
||||
items: readonly T[],
|
||||
predicate: (item: T, index: number, items: readonly T[]) => boolean,
|
||||
): T | undefined {
|
||||
for (let i = items.length - 1; i >= 0; i -= 1) {
|
||||
const item = items[i]
|
||||
if (predicate(item, i, items)) return item
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue