Advertisement
kstoyanov

03. Piccolo js fundamentals

Jul 11th, 2020
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(args) {
  2.   const parking = {};
  3.  
  4.   args.forEach((element) => {
  5.     const [direction, carNumber] = element.split(', ');
  6.  
  7.     if (direction === 'IN') {
  8.       parking[carNumber] = carNumber;
  9.     } else {
  10.       delete parking[carNumber];
  11.     }
  12.   });
  13.  
  14.   Object.keys(parking).length !== 0 ?
  15.     Object.keys(parking)
  16.       .sort((a, b) => a.localeCompare(b))
  17.       .forEach((carNumber) => {
  18.         console.log(`${carNumber}`);
  19.       })
  20.     : console.log('Parking Lot is Empty');
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement