Skip to content

Commit 4a6e24e

Browse files
committed
update fuction in tally.js file by adding object with no prototype
1 parent 08d64f9 commit 4a6e24e

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

Sprint-2/implement/tally.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
function tally(list) {
2-
const uniqueItems = {};
3-
if(list.constructor === String){
4-
throw new Error ("Invalid Input")
5-
}
6-
for (const frequency of list){
7-
uniqueItems[frequency] = (uniqueItems[frequency] || 0) + 1;
8-
}
9-
10-
return uniqueItems;
11-
}
2+
if (!Array.isArray(list)) {
3+
throw new Error("Invalid Parameter");
4+
}
5+
6+
const uniqueItems = Object.create(null);
127

8+
for (const item of list) {
9+
uniqueItems[item] = (uniqueItems[item] || 0) + 1;
10+
}
11+
12+
return uniqueItems;
13+
}
1314

1415
module.exports = tally;

0 commit comments

Comments
 (0)