Skip to content

Commit ae23446

Browse files
committed
fix: update tally function to create empty object and add test for inherited properties
1 parent 27c9c9d commit ae23446

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

Sprint-2/implement/tally.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ function tally(arr) {
33
throw new Error();
44
}
55

6-
let result = {};
6+
let result = Object.create(null);
77

88
for (const element of arr) {
99
if (element in result) {

Sprint-2/implement/tally.test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,9 @@ describe("tally", () => {
2020
expect(() => tally(null)).toThrow();
2121
expect(() => tally(undefined)).toThrow();
2222
});
23+
24+
test("tally returns an object with no inherited properties", () => {
25+
const result = tally(["a", "b", "a"]);
26+
expect(Object.getPrototypeOf(result)).toBeNull();
27+
});
2328
});

0 commit comments

Comments
 (0)