Skip to content

Commit 18b106c

Browse files
authored
change the code based on the comment
1 parent f8f0510 commit 18b106c

File tree

5 files changed

+28
-19
lines changed

5 files changed

+28
-19
lines changed

Sprint-2/debug/author.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ const author = {
1010
age: 40,
1111
alive: true,
1212
};
13-
console.log(author)
13+
for (let value of Object.values(author)) {
14+
console.log(value);
15+
}
1416

1517
// for (const value of author) {
1618
// console.log(author);

Sprint-2/implement/contains.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
function contains(object, properityValue){
1+
function contains(object, propertyValue){
22
if (typeof object !== 'object' || object === null || Array.isArray(object)) {
33
return false;
44
}
55

6-
return properityValue in object;
6+
return Object.hasOwn(object, propertyValue);
77

88
}
99
module.exports = contains;

Sprint-2/implement/querystring.js

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

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

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

19-
return queryParams;
19+
}
2020
}
2121

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

Sprint-2/implement/tally.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@ function tally(input) {
33
throw new Error("Input must be an array");
44
}
55

6-
const counts = {};
6+
const counts = Object.create(null); // no prototype
77
for (let item of input) {
88
counts[item] = (counts[item] || 0) + 1;
99
}
1010

1111
return counts;
1212
}
1313

14+
15+
1416
module.exports = tally;
17+

Sprint-2/implement/tally.test.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ const tally = require("./tally.js");
2323
// Given an empty array
2424
// When passed to tally
2525
// Then it should return an empty object
26-
test.todo("tally on an empty array returns an empty object");
2726
test("tally on an empty array returns an empty object", () => {
2827
const input = [];
2928
const result = tally(input);
@@ -39,6 +38,12 @@ test("tally on an array with duplicate items returns correct counts", () => {
3938
expect(result).toEqual({apple: 3, banana: 2, orange: 1});
4039
});
4140

41+
test("tally on an array with duplicate items returns correct counts", () => {
42+
const input = ['toString', 'toString', 'valueOf', 'toString', 'valueOf'];
43+
const result = tally(input);
44+
expect(result).toEqual({toString: 3, valueOf: 2});
45+
});
46+
4247
// Given an invalid input like a string
4348
// When passed to tally
4449
// Then it should throw an error

0 commit comments

Comments
 (0)