Advertisement
bebo231312312321

Untitled

Mar 9th, 2023
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function garage(input) {
  2.     let garages = {}
  3.  
  4.     for (let line of input) {
  5.         let[garage, carInfo] = line.split(" - ");
  6.  
  7.         if(!garages.hasOwnProperty(garage)){
  8.             garages[garage] = [];
  9.         }
  10.  
  11.         garages[garage].push(carInfo);
  12.     }
  13.  
  14.     let output = "";
  15.  
  16.     Object.entries(garages).sort((a, b) => a[0] - b[0]).forEach(([garage, cars]) => {
  17.         output += `Garage № ${garage}\n`;
  18.         for (let currCar of cars) {
  19.             currCar = currCar.replace(/: /g, ' - ');
  20.             output += `--- ${currCar}\n`  
  21.         }
  22.     });
  23.  
  24.     console.log(output);
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement