Advertisement
pacho_the_python

flights

Mar 10th, 2023
657
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function flightSchedule(data) {
  2.     let allFlights = data.shift()
  3.     let flightStatus = data.shift()
  4.     let flightsArr = []
  5.     let currentStatus = data.shift()
  6.     class Flight {
  7.         constructor(id, destination, status) {
  8.             this.id = id
  9.             this.destination = destination
  10.             this.status = status
  11.         }
  12.     }
  13.  
  14.     function getFlight(currentId, someArr) {
  15.         for (const someFlight of someArr) {
  16.             if(someFlight.id === currentId) {
  17.                 return someFlight
  18.             }
  19.         }
  20.         return false
  21.     }
  22.  
  23.     for (const line of allFlights) {
  24.         let flightId = line.split(' ')[0]
  25.         let areaDestination = line.split(' ')[1]
  26.         let newFlight = new Flight(flightId, areaDestination, '')
  27.         flightsArr.push(newFlight)
  28.     }
  29.  
  30.     for (const currentLine of flightStatus) {
  31.         let currentFlightId = currentLine.split(' ')[0]
  32.         let changedStatus = currentLine.split(' ')[1]
  33.         let plane = getFlight(currentFlightId, flightsArr)
  34.         if(plane) {
  35.             plane.status = changedStatus
  36.         }
  37.     }
  38.  
  39.     if (currentStatus[0] === 'Ready to fly') {
  40.         let readyToFly = flightsArr.filter(obj => obj.status === '')
  41.         for (const ready of readyToFly) {
  42.             ready.status = 'Ready to fly'
  43.             console.log(`{ Destination: '${ready.destination}', Status: '${ready.status}' }`)
  44.         }
  45.     } else {
  46.         let cancelledFlight = flightsArr.filter(obj => obj.status === 'Cancelled')
  47.         for (const cansel of cancelledFlight) {
  48.             console.log(`{ Destination: '${cansel.destination}', Status: '${cansel.status}' }`)
  49.         }
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement