Advertisement
bebo231312312321

Untitled

Oct 6th, 2024
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function autoEngineeringCompany(arr) {
  2.     const company = arr.reduce((acc, el) => {
  3.         let [brand, model, count] = el.split(' | ');
  4.         acc[brand] = acc[brand] || {};
  5.         acc[brand][model] = (acc[brand][model] || 0) + Number(count);
  6.         return acc;
  7.     }, {});
  8.  
  9.     Object.entries(company).forEach(([brand, models]) => {
  10.         console.log(brand);
  11.         Object.entries(models).forEach(([model, count]) => console.log(`###${model} -> ${count}`));
  12.     });
  13. }
  14.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement