File tree
Expand file treeCollapse file tree1 file changed
+6
-6
lines changed Expand file treeCollapse file tree1 file changed
+6
-6
lines changed Original file line number | Diff line number | Diff line change |
---|
@@ -98,16 +98,16 @@ for (let i = 0; i < MINUTES_IN_A_YEAR; i++) {
|
98 | 98 | ### Use explanatory variables
|
99 | 99 | **Bad:**
|
100 | 100 | ```javascript
|
101 |
| -const cityStateRegex = /^(.+)[,\\s]+(.+?)\s*(\d{5})?$/; |
102 |
| -saveCityState(cityStateRegex.match(cityStateRegex)[1], cityStateRegex.match(cityStateRegex)[2]); |
| 101 | +const address = 'One Infinite Loop, Cupertino 95014'; |
| 102 | +const cityStateRegex = /^[^,\\]+[,\\\s]+(.+?)\s*(\d{5})?$/; |
| 103 | +saveCityState(address.match(cityStateRegex)[1], address.match(cityStateRegex)[2]); |
103 | 104 | ```
|
104 | 105 |
|
105 | 106 | **Good**:
|
106 | 107 | ```javascript
|
107 |
| -const cityStateRegex = /^(.+)[,\\s]+(.+?)\s*(\d{5})?$/; |
108 |
| -const match = cityStateRegex.match(cityStateRegex) |
109 |
| -const city = match[1]; |
110 |
| -const state = match[2]; |
| 108 | +const address = 'One Infinite Loop, Cupertino 95014'; |
| 109 | +const cityStateRegex = /^[^,\\]+[,\\\s]+(.+?)\s*(\d{5})?$/; |
| 110 | +const [, city, state] = address.match(cityStateRegex); |
111 | 111 | saveCityState(city, state);
|
112 | 112 | ```
|
113 | 113 | **[⬆ back to top](#table-of-contents)**
|
|
You can’t perform that action at this time.
0 commit comments