Skip to content

Commit 3fd28f5

Browse files
author
Dmitry Porokhnya
committed
Issue HowProgrammingWorks#4: Task four.
1 parent cdc1347 commit 3fd28f5

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

Exercises/4-count-types.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
'use strict';
22

3-
const countTypesInArray = null;
3+
4+
const countTypesInArray = arr => {
5+
const obj = {};
6+
for (const item of arr) {
7+
const type = typeof item;
8+
type in obj ? obj[type]++ : obj[type] = 1;
9+
}
10+
return obj;
11+
};
412

513
module.exports = { countTypesInArray };

0 commit comments

Comments
 (0)