Skip to content

Commit 2a62f58

Browse files
committed
implement tally function
1 parent 3423b50 commit 2a62f58

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

‎Sprint-2/implement/tally.js‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1-
function tally() {}
1+
function tally(array) {
2+
if (typeof array === "string") {
3+
throw new Error("Input should be an array");
4+
}
5+
6+
let tallySet = {};
7+
8+
for (let item of array) {
9+
if (!tallySet[item]) {
10+
tallySet[item] = 1;
11+
} else {
12+
tallySet[item] += 1;
13+
}
14+
}
15+
return tallySet;
16+
}
217

318
module.exports = tally;

0 commit comments

Comments
 (0)