Skip to content

Commit 12d6200

Browse files
committed
Address review: fix address log, harden contains tests, null-prototype tally
1 parent 7efd118 commit 12d6200

3 files changed

Lines changed: 6 additions & 9 deletions

File tree

‎Sprint-2/debug/address.js‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ const address = {
1212
postcode: "XYZ 123",
1313
};
1414

15-
console.log(`My house number is ${address.houseNumber}`);
16-
17-
18-
/* BUG: address[0] is undefined because objects aren't indexed by number.
19-
FIX: useed the property name: address.houseNumber
20-
console.log(`My house number is ${address.houseNumber}`);
15+
// BUG: address[0] is undefined because plain objects aren't indexed by number.
16+
// FIX: use the property name address.houseNumber
17+
console.log('My house number is ' + address.houseNumber);

‎Sprint-2/implement/contains.test.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ test("returns false when property does not exist", () => {
4848
// (careful: typeof [] and typeof null are both "object")
4949

5050
test("throws an error when given an array", () => {
51-
expect(() => contains([3, 4, 5], "a")).toThrow(
51+
expect(() => contains([3, 4, 5], "0")).toThrow(
5252
new Error("contains requires an object")
5353
);
5454
});
@@ -60,7 +60,7 @@ test("throws an error when given a null", () => {
6060
});
6161

6262
test("throws an error when given a string", () => {
63-
expect(() => contains("hellow", "a")).toThrow(
63+
expect(() => contains("hellow", "0")).toThrow(
6464
new Error("contains requires an object")
6565
);
6666
});

‎Sprint-2/implement/tally.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ function tally(items) {
22
if (!Array.isArray(items)) {
33
throw new Error("tally requires an array");
44
}
5-
const counts = {};
5+
const counts = Object.create(null);
66
for (const item of items) {
77
counts[item] = (counts[item] ?? 0) + 1;
88
}

0 commit comments

Comments
 (0)