Advertisement
PPetkov2000

JS Fundamentals: Objects - Flight Schedule

Dec 8th, 2019
1,016
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(params) {
  2.   let flights = params[0];
  3.   let newFlightsStatus = params[1];
  4.   let flightStatus = params[2].toString();
  5.   let newFlights = {};
  6.  
  7.   for (let flight of flights) {
  8.     let [sector, destination] = flight.split(" ");
  9.     newFlights[sector] = {
  10.       Destination: destination,
  11.       Status: flightStatus
  12.     };
  13.   }
  14.  
  15.   for (let newFlight of newFlightsStatus) {
  16.     let [sector, status] = newFlight.split(" ");
  17.     if (newFlights.hasOwnProperty(sector)) {
  18.       newFlights[sector].Status = status;
  19.     }
  20.   }
  21.  
  22.   for (let flight in newFlights) {
  23.     if (newFlights[flight].Status === flightStatus) {
  24.       console.log(newFlights[flight]);
  25.     }
  26.   }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement