Advertisement
kStoikow

arr

Oct 5th, 2019
325
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input) {
  2.     let garages = {};
  3.  
  4.     for (const 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.  
  15.     let output = '';
  16.      Object.entries(garages)
  17.         .forEach(([garage, cars]) => {
  18.             output += `Garage № ${garage}\n`;
  19.  
  20.             for (let currCar of cars) {
  21.                 while (currCar.includes(': ')) {
  22.                     currCar = currCar.replace(': ', ' - ');
  23.                 }
  24.  
  25.                 output += `--- ${currCar}\n`;
  26.             }
  27.         });
  28.     console.log(output);
  29.  
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement