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
setarraysdeduplicationreadability
Dedupe with a Set and spread back to an array for readability
To add a unique item to a list, build a Set and spread it to an array rather than hand-rolling index checks.
PR: frontpage-web · org-mining-hist-2026-06Created: Jun 18, 2026
Bad example
Old codetypescript
| 1 | if (this.state.visited.indexOf(url) === -1) { |
| 2 | this.setState({ visited: this.state.visited.concat(url) }); |
| 3 | } |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | const set = new Set(this.state.visited); |
| 2 | set.add(url); |
| 3 | this.setState({ visited: [...set] }); |
Explanation (EN)
Objašnjenje (HR)