Rules Hub
Coding Rules Library
← Back to all rules
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
fullstack ruleP2universalStack: TypeScript / JavaScript
arraysclean-codecorrectness
Use find (not filter + loop) when you expect a single match
If at most one element matches, filter followed by a forEach that overwrites is wasteful and bug-prone; use find and handle the single result.
PR: hegnar-ws · org-mining-hist-2026-06Created: Jun 18, 2026
Bad example
Old codetypescript
| 1 | const matches = thumbnails.filter((t) => t.media.some((r) => r.id === m.id)); |
| 2 | matches.forEach((t) => { /* only the last one is used */ }); |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | const thumbnail = thumbnails.find((t) => t.media.some((r) => r.id === m.id)); |
| 2 | if (thumbnail) { /* use it */ } |
Explanation (EN)
Objašnjenje (HR)