menu
manual-find
Prefer find over a loop returning the first matching element
A loop that returns its first match and otherwise returns undefined implements find manually.
Instead, you SHOULD return the result of find directly.
Reported
1function firstPositive(values: int32[]): int32 | undefined {2 for (const value of values) {3 if (value > 0) {4 return value;5 }6 }7 return undefined;8}Accepted
1function firstPositive(values: int32[]): int32 | undefined {2 return values.find((value) => value > 0);3}