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: JavaScript/TypeScript
arraysreducefunctionalreadability
Use reduce to build an aggregate instead of manual accumulation
When building a single accumulated value or object from an array, prefer reduce over a manual loop pushing into an external variable.
PR: vinify-frontend · org-mining-hist-2026-06Created: Jun 19, 2026
Bad example
Old codetypescript
| 1 | const result = {}; |
| 2 | tableColumns.forEach(c => { result[c.id] = c.visible; }); |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | const result = tableColumns.reduce((acc, c) => ({ ...acc, [c.id]: c.visible }), {}); |
Explanation (EN)
Objašnjenje (HR)