Skip to content

Commit

Permalink
chore: a note on _findLast
Browse files Browse the repository at this point in the history
  • Loading branch information
kirillgroshkov committed Mar 27, 2024
1 parent 95062e6 commit 94236f7
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/array/array.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ export function _sortDescBy<T>(items: T[], mapper: Mapper<T, any>, mutate = fals

/**
* Like items.find(), but it tries to find from the END of the array.
*
* Node 18+ supports native array.findLast() - use that.
* iOS Safari only has it since 15.4
*/
export function _findLast<T>(items: T[], predicate: Predicate<T>): T | undefined {
return [...items].reverse().find(predicate)
Expand Down

0 comments on commit 94236f7

Please sign in to comment.