Skip to content
Permalink
Newer
Older
100644 45 lines (42 sloc) 1.12 KB
May 27, 2020
1
function autoEngineeringCompany(input) {
May 27, 2020
2
// Mask - https://git.io/Jfre9
May 27, 2020
3
let cars = {};
4
5
input.map(data => {
6
let [make, model, count] = data.split(' | ');
7
count = +count;
8
!cars.hasOwnProperty(make) ? cars[make] = {} : 'pass';
9
cars[make].hasOwnProperty(model) ? cars[make][model] += count : cars[make][model] = count;
10
});
11
12
for (let [make, models] of Object.entries(cars)) {
13
console.log(make);
14
for (let [model, count] of Object.entries(models)) {
15
console.log(`###${model} -> ${count}`);
16
}
17
}
18
}
19
20
autoEngineeringCompany([
21
'Audi | Q7 | 1000',
22
'Audi | Q6 | 100',
23
'BMW | X5 | 1000',
24
'BMW | X6 | 100',
25
'Citroen | C4 | 123',
26
'Volga | GAZ-24 | 1000000',
27
'Lada | Niva | 1000000',
28
'Lada | Jigula | 1000000',
29
'Citroen | C4 | 22',
30
'Citroen | C5 | 10']
31
); // Should return:
32
// Audi
33
// ###Q7 -> 1000
34
// ###Q6 -> 100
35
// BMW
36
// ###X5 -> 1000
37
// ###X6 -> 100
38
// Citroen
39
// ###C4 -> 145
40
// ###C5 -> 10
41
// Volga
42
// ###GAZ-24 -> 1000000
43
// Lada
44
// ###Niva -> 1000000
45
// ###Jigula -> 1000000