forked from denulemos/programming-training
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ejer47.js
25 lines (21 loc) · 790 Bytes
/
ejer47.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// Objeto mock
const users = [
{name: 'denu', hobbie: ['cine', 'musica', 'bordado']},
{name: 'deno', hobbie: ['surf', 'cocina', 'tecnologia']},
{name: 'denu', hobbie: ['cine', 'musica', 'tecnologia']},
{name: 'denu', hobbie: ['cocina', 'surf', 'tecnologia']},
{name: 'denu', hobbie: ['cine', 'bordado', 'cocina']},
{name: 'denu', hobbie: ['cine', 'musica', 'tecnologia']},
{name: 'denu', hobbie: ['surf', 'cocina', 'bordado']},
{name: 'denu', hobbie: ['bordado', 'musica', 'cocina']},
];
const getHobbiesCount = (users) => {
let hobbiesMap = {};
for (object of users){
for (hobbie of object.hobbie){
hobbiesMap[hobbie] = (hobbiesMap[hobbie] || 0) + 1;
}
}
return hobbiesMap;
}
module.exports = getHobbiesCount;