Skip to content

Commit 887c779

Browse files
authored
Rename state to zipCode to avoid confusion
Destructuring state using the regex was a little bit ambiguous since there is no state in the address (zip code instead).
1 parent 383dd49 commit 887c779

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

README.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -102,16 +102,17 @@ setTimeout(() => {
102102
**Bad:**
103103
```javascript
104104
const address = 'One Infinite Loop, Cupertino 95014';
105-
const cityStateRegex = /^[^,\\]+[,\\\s]+(.+?)\s*(\d{5})?$/;
105+
const city
106+
Regex = /^[^,\\]+[,\\\s]+(.+?)\s*(\d{5})?$/;
106107
saveCityState(address.match(cityStateRegex)[1], address.match(cityStateRegex)[2]);
107108
```
108109

109110
**Good**:
110111
```javascript
111112
const address = 'One Infinite Loop, Cupertino 95014';
112-
const cityStateRegex = /^[^,\\]+[,\\\s]+(.+?)\s*(\d{5})?$/;
113-
const [, city, state] = address.match(cityStateRegex);
114-
saveCityState(city, state);
113+
const cityZipCodeRegex = /^[^,\\]+[,\\\s]+(.+?)\s*(\d{5})?$/;
114+
const [, city, zipCode] = address.match(cityZipCodeRegex);
115+
saveCityState(city, zipCode);
115116
```
116117
**[⬆ back to top](#table-of-contents)**
117118

0 commit comments

Comments
 (0)