Skip to content

Commit c1a83b4

Browse files
authored
changing the format of the code
1 parent bc33d58 commit c1a83b4

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

Sprint-2/implement/querystring.js

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
11
function parseQueryString(queryString) {
2+
const queryParams = {};
3+
if (!queryString) return queryParams;
24

3-
const queryParams = {};
4-
if (!queryString ) return queryParams;
5+
const keyValuePairs = queryString.split("&");
56

6-
const keyValuePairs = queryString.split("&");
7-
8-
for (const pair of keyValuePairs) {
9-
const index = pair.indexOf("=");
10-
if (index === -1) {
11-
queryParams[decodeURIComponent(pair)] = undefined
12-
} else {
13-
const key = decodeURIComponent (pair.slice(0, index));
14-
const value = decodeURIComponent (pair.slice (index + 1));
15-
queryParams[key] = value;
16-
}
17-
18-
return queryParams;
7+
for (const pair of keyValuePairs) {
8+
const index = pair.indexOf("=");
9+
if (index === -1) {
10+
queryParams[decodeURIComponent(pair)] = undefined;
11+
} else {
12+
const key = decodeURIComponent(pair.slice(0, index));
13+
const value = decodeURIComponent(pair.slice(index + 1));
14+
queryParams[key] = value;
15+
}
1916

17+
return queryParams;
2018
}
2119
}
2220

23-
module.exports = parseQueryString;
21+
module.exports = parseQueryString;

0 commit comments

Comments
 (0)