Advertisement
Guest User

Untitled

a guest
May 23rd, 2021
408
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function piccolo(input) {
  2.     let obj = {}
  3.  
  4.     for (let element of input) {
  5.         let [direction, carNumber] = element.split(`, `)
  6.         if (direction == `IN`) {
  7.             if (!obj.hasOwnProperty(carNumber)) {
  8.                 obj[carNumber] = null
  9.             }
  10.         } else if (direction == `OUT`) {
  11.             delete obj[carNumber]
  12.         }
  13.  
  14.     }
  15.  
  16.     let sorted = Object.keys(obj)
  17.     if (sorted.length >= 1) {
  18.         sorted = sorted.sort()
  19.         for (let element of sorted) {
  20.             console.log(element)
  21.         }
  22.     } else {
  23.         console.log(`Parking Lot is Empty`)
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement