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).
frontend ruleP2universalStack: javascript
performancedryreadabilityarrays
Reuse a single lookup result instead of searching repeatedly
Find an item once and derive all needed fields from that result rather than calling find multiple times for the same element.
PR: hegnar-forum-web · org-mining-hist-2026-06Created: Jun 20, 2026
Bad example
Old codetypescript
| 1 | const emoji = categories.find(c => c.id === category.id)?.emoji; |
| 2 | const name = categories.find(c => c.id === category.id)?.name; |
| 3 | const url = categories.find(c => c.id === category.id)?.urlname; |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | const categoryObj = categories.find(c => c.id === category.id); |
| 2 | const emoji = categoryObj?.emoji ?? '🍆'; |
| 3 | const name = categoryObj?.name; |
| 4 | const url = categoryObj?.urlname; |
Explanation (EN)
Objašnjenje (HR)