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

Skip to content

Commit cea298d

Browse files
Merge pull request ryanmcdermott#37 from SebastienElet/feat/use-destructuring
Use destructuring for explanatory variables
2 parents 6794252 + f446783 commit cea298d

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

README.md

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

0 commit comments

Comments
 (0)