Advertisement
bebo231312312321

Untitled

Oct 7th, 2024
15
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function autoEngineeringCompany(arr) {
  2.     class AutoEngineeringCompany {
  3.         constructor() {
  4.             this.brands = {};
  5.         }
  6.  
  7.         addProductionData = ([brand, model, count]) =>
  8.             this.brands[brand] = { ...this.brands[brand], [model]: (this.brands[brand]?.[model] || 0) + Number(count) };
  9.  
  10.         displayProductionData = () =>
  11.             Object.entries(this.brands).forEach(([brand, models]) => {
  12.                 console.log(brand);
  13.                 Object.entries(models).forEach(([model, count]) => console.log(`###${model} -> ${count}`));
  14.             });
  15.     }
  16.  
  17.     const company = new AutoEngineeringCompany();
  18.     arr.map(e => e.split(' | ')).forEach(e => company.addProductionData(e));
  19.     company.displayProductionData();
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement