Advertisement
Kamend1

08.Piccolo

Mar 12th, 2025
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function picollo (carArr) {
  2.     let parkingLot = [];
  3.  
  4.     for (let i = 0; i < carArr.length; i++) {
  5.         let [command, plate] = carArr[i].split(', ');
  6.         if (command === 'IN') {
  7.             if (!parkingLot.includes(plate)) {
  8.                 parkingLot.push(plate);
  9.             }
  10.         } else if (command === 'OUT') {
  11.             let index = parkingLot.indexOf(plate);
  12.             if (index !== -1) parkingLot.splice(index, 1);
  13.         }
  14.     }
  15.  
  16.     if (parkingLot.length > 0) {
  17.         let sortedArr = parkingLot.sort();
  18.         console.log(parkingLot.join('\n'));
  19.     } else {
  20.         console.log("Parking Lot is Empty")
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement