Skip to content

Commit 393e1ff

Browse files
committed
fix: acculmulator object has not prototype, to stop looking up string properties in prototype chain
1 parent 7ecd4d5 commit 393e1ff

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

Sprint-2/implement/tally.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ function tally(list) {
22
if (!Array.isArray(list)) {
33
throw new TypeError("Invalid input: not an array");
44
}
5+
56
return list.reduce((acc, curr) => {
67
if (typeof curr !== "string" && typeof curr !== "number") {
78
throw new TypeError(
@@ -10,7 +11,8 @@ function tally(list) {
1011
}
1112
acc[curr] = (acc[curr] ?? 0) + 1;
1213
return acc;
13-
}, {});
14+
}, Object.create(null));
1415
}
1516

17+
console.log(tally(["toString", "toString"]));
1618
module.exports = tally;

0 commit comments

Comments
 (0)