Skip to content

Commit aaeb462

Browse files
authored
Update tally.js
1 parent f8ce3aa commit aaeb462

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

‎Sprint-2/implement/tally.js‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1-
function tally() {}
1+
function tally(items) {
2+
if (!Array.isArray(items)) {
3+
throw new TypeError("Input must be an array");
4+
}
5+
6+
const uniqueItems = [...new Set(items)].sort();
7+
8+
const counts = {};
9+
for (const item of uniqueItems) {
10+
counts[item] = items.filter(x => x === item).length;
11+
}
12+
13+
return counts;
14+
}
215

316
module.exports = tally;

0 commit comments

Comments
 (0)