Advertisement
bebo231312312321

Untitled

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