Advertisement
bebo231312312321

Untitled

Oct 7th, 2024
20
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function vehicleProduction(arr) {
  2.     class VehicleFactory {
  3.         manufacturers = {};
  4.         addRecord = ([man, mod, qty]) => ((this.manufacturers[man] ||= {})[mod] = (this.manufacturers[man][mod] || 0) + +qty);
  5.         showRecords = () => Object.entries(this.manufacturers).forEach(([man, mods]) => {
  6.             console.log(man);
  7.             Object.entries(mods).forEach(([mod, qty]) => console.log(`###${mod} -> ${qty}`));
  8.         });
  9.     }
  10.     const factory = new VehicleFactory();
  11.     arr.forEach(e => factory.addRecord(e.split(' | ')));
  12.     factory.showRecords();
  13. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement