File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -112,14 +112,16 @@ for (var i = 0; i < MINUTES_IN_A_YEAR; i++) {
112112### Use explanatory variables
113113** Bad:**
114114``` 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 ]);
117118```
118119
119120** Good** :
120121``` 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);
123125saveCityState (city, state);
124126```
125127** [ ⬆ back to top] ( #table-of-contents ) **
You can’t perform that action at this time.
0 commit comments