maymunskoa

03. Piccolo (Assoc Arrays)

Mar 6th, 2020
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input){
  2. let cars = new Map();
  3.  
  4. for (const line of input) {
  5.     let [direction, plate] = line.split(', ');
  6.     cars.set(plate,direction);
  7. }
  8.  
  9. let output = (Array.from(cars)).filter(pair=>{
  10.     return pair[1] !== 'OUT';
  11. });
  12.  
  13. if(output.length !== 0){
  14.     output.sort((a,b)=>{
  15.         return a[0].localeCompare(b[0]);
  16.     }).forEach(pair=>{
  17.         console.log(pair[0]);
  18.     });
  19. }else{
  20.     console.log(`Parking Lot is Empty`);
  21. }
  22.        
  23.  
  24. }
Advertisement
Add Comment
Please, Sign In to add comment