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
stringsreadabilityregex
Use replace with a global regex instead of split().join()
To swap all occurrences of a character, str.replace(/x/g, 'y') is clearer than str.split('x').join('y').
PR: frontpage-web · org-mining-hist-2026-06Created: Jun 18, 2026
Bad example
Old codejavascript
| 1 | item.toLowerCase().split(' ').join('-').replace('&', 'and'); |
Explanation (EN)
Objašnjenje (HR)
Good example
New codejavascript
| 1 | item.toLowerCase().replace(/ /g, '-').replace(/&/g, 'and'); |
Explanation (EN)
Objašnjenje (HR)