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
data-structuresperformanceapi-design
Return a Map keyed by id when callers do repeated lookups
If consumers repeatedly look items up by id, return a Map/keyed object instead of an array so lookups are O(1) and call-site code is simpler.
PR: hegnar-ws · org-mining-hist-2026-06Created: Jun 18, 2026
Bad example
Old codetypescript
| 1 | const logos = await getTickerLogos(); // array |
| 2 | const logo = logos.find((l) => l.insref === id); |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | const logoMap = await getTickerLogos(); // Map<insref, url> |
| 2 | const logo = logoMap.get(id); |
Explanation (EN)
Objašnjenje (HR)