Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input) {
- let garages = {};
- for (const line of input) {
- let [garage, carInfo] = line.split(' - ');
- if (!garages.hasOwnProperty(garage)) {
- garages[garage] = [];
- }
- garages[garage].push(carInfo);
- }
- let output = '';
- Object.entries(garages)
- .forEach(([garage, cars]) => {
- output += `Garage № ${garage}\n`;
- for (let currCar of cars) {
- while (currCar.includes(': ')) {
- currCar = currCar.replace(': ', ' - ');
- }
- output += `--- ${currCar}\n`;
- }
- });
- console.log(output);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement