Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function autoEngineeringCompany(input) {
- const cars = new Map();
- input.forEach((line) => {
- const tokens = line.split(' | ');
- const [brand, model, count] = tokens;
- if (!cars.get(brand)) {
- cars.set(brand, new Map());
- }
- if (!cars.get(brand).get(model)) {
- cars.get(brand).set(model, 0);
- }
- cars.get(brand).set(model, cars.get(brand).get(model) + Number(count));
- });
- for (const [brand, modelCount] of cars) {
- console.log(brand);
- for (const [model, count] of modelCount) {
- console.log(`###${model} -> ${count}`);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement