File tree 1 file changed +6
-4
lines changed
1 file changed +6
-4
lines changed Original file line number Diff line number Diff line change @@ -112,14 +112,16 @@ for (var i = 0; i < MINUTES_IN_A_YEAR; i++) {
112
112
### Use explanatory variables
113
113
** Bad:**
114
114
``` javascript
115
- const cityStateRegex = / ^ (. + )[,\\ s] + (. +? )\s * (\d {5} )? $ / ;
116
- saveCityState (cityStateRegex .match (cityStateRegex)[1 ], cityStateRegex .match (cityStateRegex)[2 ]);
115
+ const address = ' One Infinite Loop, Cupertino 95014' ;
116
+ const cityStateRegex = / ^ [^ ,\\ ] + [,\\ \s ] + (. +? )\s * (\d {5} )? $ / ;
117
+ saveCityState (address .match (cityStateRegex)[1 ], address .match (cityStateRegex)[2 ]);
117
118
```
118
119
119
120
** Good** :
120
121
``` javascript
121
- const cityStateRegex = / ^ (. + )[,\\ s] + (. +? )\s * (\d {5} )? $ / ;
122
- const [, city , state ] = cityStateRegex .match (cityStateRegex);
122
+ const address = ' One Infinite Loop, Cupertino 95014' ;
123
+ const cityStateRegex = / ^ [^ ,\\ ] + [,\\ \s ] + (. +? )\s * (\d {5} )? $ / ;
124
+ const [, city , state ] = address .match (cityStateRegex);
123
125
saveCityState (city, state);
124
126
```
125
127
** [ ⬆ back to top] ( #table-of-contents ) **
You can’t perform that action at this time.
0 commit comments