Advertisement
miroLLL

ANOTHA

Jun 5th, 2020
946
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solveCurrentProblem(input){
  2.  
  3.     let map = new Map();
  4.  
  5.     for(let productInfo of input){
  6.         let [brand, model, quantity] = productInfo.split(/\s+\|\s+/);
  7.  
  8.         if(map.has(brand) === false){
  9.             map.set(brand, new Map());
  10.         }
  11.  
  12.         if(map.get(brand).has(model) === false){
  13.             map.get(brand).set(model, 0);
  14.         }
  15.  
  16.         map.get(brand).set(model, map.get(brand).get(model) + +quantity);
  17.     }
  18.  
  19.     Array.from(map.keys()).forEach(brand => {
  20.  
  21.         console.log(brand);
  22.  
  23.         Array.from(map.get(brand)).forEach(model => {
  24.             console.log(`###${model.join(" -> ")}`);
  25.         })
  26.     })
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement