Skip to content

Commit 7a17d26

Browse files
Refactor parseQueryString function for clarity and consistency in handling key-value pairs
1 parent af31865 commit 7a17d26

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

Sprint-2/implement/querystring.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ function parseQueryString(queryString) {
1010
if (!pair) {
1111
continue;
1212
}
13-
const equalIndex = pair.indexOf("=");
14-
if (equalIndex === -1) {
13+
const index = pair.indexOf("=");
14+
if (index === -1) {
1515
queryParams[pair] = "";
16-
continue;
16+
} else {
17+
const key = pair.slice(0, index);
18+
const value = pair.slice(index + 1);
19+
queryParams[key] = value;
1720
}
18-
const key = pair.substring(0, equalIndex);
19-
const value = pair.substring(equalIndex + 1);
20-
queryParams[key] = value;
2121
}
22-
2322
return queryParams;
2423
}
24+
console.log(parseQueryString("equation=x=y+1&sound=none"));
2525

2626
module.exports = parseQueryString;

0 commit comments

Comments
 (0)