Advertisement
tetris555

piccolo

Nov 4th, 2022 (edited)
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve2(arr) {
  2.     const parkingLot = new Set();
  3.  
  4.     for (const entry of arr) {
  5.         const [dir, plate] = entry.split(', ');
  6.  
  7.         switch (dir) {
  8.             case 'IN': {
  9.                 parkingLot.add(plate);
  10.                 break;
  11.             }
  12.             case 'OUT': {
  13.                 parkingLot.delete(plate);
  14.                 break;
  15.             }
  16.         }
  17.     }
  18.    
  19.     if (parkingLot.size > 0) {
  20.         [...parkingLot]
  21.             .sort((a, b) => a.localeCompare(b))
  22.             .forEach(carNumber => {
  23.                 console.log(carNumber);
  24.         });
  25.     }
  26.     else {
  27.         console.log('Parking Lot is Empty');
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement