Advertisement
Marin171

Auto-Engineering Company

Jun 14th, 2023
18
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. function solve(input) {
  2. const cars = new Map;
  3.  
  4. for (const line of input) {
  5. let [brand, model, quantity] = line.split(" | ");
  6. quantity = Number(quantity);
  7.  
  8. if (!cars.has(brand)) {
  9. cars.set(brand, {});
  10. }
  11. if (!cars.get(brand).hasOwnProperty(model)) {
  12. cars.get(brand)[model] = quantity;
  13. } else {
  14. cars.get(brand)[model] += quantity;
  15. }
  16. }
  17. for (const car of cars) {
  18. console.log(car[0]);
  19. const models = car[1];
  20. for (const model of Object.keys(models)) {
  21. console.log(`###${model} -> ${models[model]}`)
  22. }
  23. }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement