Advertisement
didkoslawow

Untitled

Feb 25th, 2023
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function fligthSchedule(input) {
  2.   const flightList = input.shift();
  3.   const changedStatuses = input.shift();
  4.   const status = input.shift().join(' ');
  5.   const flights = {};
  6.  
  7.   for (const flight of flightList) {
  8.     const [flightNumber, ...rest] = flight.split(' ');
  9.     const destination = rest.join(' ');
  10.     flights[destination] = flightNumber;
  11.   }
  12.  
  13.   for (const changeStatus of changedStatuses) {
  14.     const [flightNumber, changedStatus] = changeStatus.split(' ');
  15.  
  16.     for (key in flights) {
  17.       if (flightNumber === flights[key]) {
  18.         flights[key] = changedStatus;
  19.         break;
  20.       }
  21.     }
  22.   }
  23.  
  24.   if (status === 'Cancelled') {
  25.     for (const destination in flights) {
  26.       if (flights[destination] === 'Cancelled') {
  27.         console.log(
  28.           `{ Destination: '${destination}', Status: '${flights[destination]}' }`
  29.         );
  30.       }
  31.     }
  32.   } else {
  33.     for (const destination in flights) {
  34.       if (flights[destination] !== 'Cancelled') {
  35.         flights[destination] = 'Ready to fly';
  36.         console.log(
  37.           `{ Destination: '${destination}', Status: '${flights[destination]}' }`
  38.         );
  39.       }
  40.     }
  41.   }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement