Skip to content

Commit df05b38

Browse files
authored
Refactor tally function to use Object.hasOwn
1 parent 514a218 commit df05b38

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

‎Sprint-2/implement/tally.js‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ function tally(items) {
44
}
55

66
return items.reduce((acc, item) => {
7-
acc[item] = (acc[item] || 0) + 1;
7+
if (Object.hasOwn(acc, item)) {
8+
acc[item] += 1;
9+
} else {
10+
acc[item] = 1;
11+
}
812
return acc;
913
}, {});
1014
}

0 commit comments

Comments
 (0)