Skip to content

Commit 1962dc2

Browse files
committed
Fix: Use Object.create(null) to avoid inherited property conflicts
1 parent cbcbe64 commit 1962dc2

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

Sprint-2/implement/tally.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ function tally(arr) {
66
throw new Error("Input must be an array");
77
}
88

9-
// Create an empty obkect to store our counts
10-
const counts = {};
9+
// Create an empty object with no inherited properties
10+
// This prevents conflicts with built in properties like "toString"
11+
const counts = Object.create(null);
1112

1213
// Loop through each item in the array one by one
1314
for (const item of arr) {

0 commit comments

Comments
 (0)