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).
backend ruleP2universalStack: TypeScript
clean-codereadabilityarrayschunking
Simplify chunking loops by stepping the index by chunk size
Instead of computing iteration counts with Number.isInteger/Math.ceil and index math, map to the needed values up front and step a for-loop by the chunk size with slice.
PR: hegnar-shareholders-ws · org-mining-hist-2026-06Created: Jun 18, 2026
Bad example
Old codetypescript
| 1 | const iterations = Number.isInteger(items.length / SIZE) |
| 2 | ? items.length / SIZE |
| 3 | : Math.ceil(items.length / SIZE); |
| 4 | for (let i = 0; i < iterations; i += 1) { |
| 5 | const chunk = items.slice(i * SIZE, (i + 1) * SIZE); |
| 6 | } |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | const values = items.map(({ insref }) => insref); |
| 2 | const groups = []; |
| 3 | for (let i = 0; i < values.length; i += SIZE) { |
| 4 | groups.push(values.slice(i, i + SIZE)); |
| 5 | } |
Explanation (EN)
Objašnjenje (HR)