Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f446783

Browse files
committed
refactor(explanatory-variables): add input example & remove first group
1 parent 19b1f36 commit f446783

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff 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);
123125
saveCityState(city, state);
124126
```
125127
**[⬆ back to top](#table-of-contents)**

0 commit comments

Comments
 (0)