We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 03e4fa7 commit fb8ea4bCopy full SHA for fb8ea4b
Sprint-2/implement/tally.js
@@ -11,17 +11,11 @@ function tally(arrayOfItems) {
11
throw new Error("Input must be an array");
12
}
13
14
- const countObject = {};
+ const countObject = Object.create(null);
15
16
for (const item of arrayOfItems) {
17
- // If the item is already counted, add 1; otherwise start at 1
18
- const itemAlreadyCounted = countObject[item] !== undefined;
19
-
20
- if (itemAlreadyCounted) {
21
- countObject[item] = countObject[item] + 1;
22
- } else {
23
- countObject[item] = 1;
24
- }
+ const currentCount = countObject[item] || 0;
+ countObject[item] = currentCount + 1;
25
26
27
return countObject;
0 commit comments