File tree Expand file tree Collapse file tree 1 file changed +6
-6
lines changed Expand file tree Collapse file tree 1 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++) {
9898### Use explanatory variables
9999** Bad:**
100100``` 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 ]);
103104```
104105
105106** Good** :
106107``` 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);
111111saveCityState (city, state);
112112```
113113** [ ⬆ back to top] ( #table-of-contents ) **
You can’t perform that action at this time.
0 commit comments