Advertisement
AreWe

Garages Ellie

Jul 13th, 2020
804
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function garage(garagesInfoInput) {
  2.     let garagesInfo = garagesInfoInput.slice();
  3.     let garagesMap = new Map();
  4.  
  5.     while (garagesInfo.length != 0) {
  6.         let [garage, carKeyValues] = garagesInfo.shift().split(' - ');
  7.  
  8.         if (!garagesMap.has(garage)) {
  9.             garagesMap.set(garage, [carKeyValues]);
  10.         } else {
  11.             let availableCars = garagesMap.get(garage);
  12.             availableCars.push(carKeyValues);
  13.             garagesMap.set(garage, availableCars);
  14.         };
  15.     }
  16.    
  17.     let output = '';
  18.    
  19.     for (let [currGarage, currCarKeyValue] of [...garagesMap]) {
  20.         output += `Garage № ${currGarage}\n`;
  21.        
  22.         for (let currCarProperties of currCarKeyValue) {
  23.             currCarProperties = currCarProperties.replace(/: /g, ' - ');
  24.             output += `--- ${currCarProperties}\n`;
  25.         }
  26.     }
  27.  
  28.     console.log(output);
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement