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 ruleP1universalStack: javascript
correctnesssetcomparisonperformance
Compare unordered id collections by size then membership, not by JSON.stringify
To detect whether a set of ids changed, compare size and membership instead of relying on JSON.stringify, which is order-sensitive and slower.
PR: hegnar-web · org-mining-hist-2026-06Created: Jun 19, 2026
Bad example
Old codejavascript
| 1 | const changed = () => |
| 2 | JSON.stringify(currentIds) !== JSON.stringify(originalIds); |
Explanation (EN)
Objašnjenje (HR)
Good example
New codejavascript
| 1 | const changed = () => { |
| 2 | const current = new Set(currentIds); |
| 3 | const original = new Set(originalIds); |
| 4 | if (current.size !== original.size) return true; |
| 5 | for (const id of current) if (!original.has(id)) return true; |
| 6 | return false; |
| 7 | }; |
Explanation (EN)
Objašnjenje (HR)