Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function FlightSchedule(input){
- let FlightsReady=[];
- let FlightsCAnceled=[];
- let selectedFligts={};
- let Status='';
- for (let i = 0; i < input.length; i++) {
- switch(i){
- case 0:
- for (const el1 of input[i]) {
- let ArrFlights3=el1.split(' ');
- let number=ArrFlights3[0];
- let Namedestination='';
- for (let j = 1; j < ArrFlights3.length; j++) {
- Namedestination+=' '+ArrFlights3[j];
- }
- let objDestination= {number:number, namedestination:Namedestination.trim()};
- FlightsReady.push(objDestination);
- }
- break;
- case 1:
- for (const el2 of input[i]) {
- let[number,status]=el2.split(' ');
- let existObj=FlightsReady.find(f => f.number == number);
- if(existObj){
- let indexObject= FlightsReady.indexOf(existObj);
- FlightsReady.splice(indexObject,1);
- FlightsCAnceled.push(existObj);
- }
- }
- break;
- case 2:
- let element3='';
- for (const el3 of input[i]) {
- element3=el3.trim();
- }
- if (element3=='Ready to fly') {
- Status='Ready to fly';
- for (const flight of FlightsReady) {
- selectedFligts[flight.namedestination]=flight.number;
- //console.log(flight);
- }
- }
- else if(element3 =='Cancelled'){
- Status='Cancelled';
- for (const flight of FlightsCAnceled) {
- selectedFligts[flight.namedestination]=flight.number;
- //console.log(flight);
- }
- }
- break;
- }
- }
- let SortedFlights= '';
- if( Status=='Cancelled'){
- SortedFlights= Object.entries(selectedFligts).sort((a,b)=> a[0].localeCompare(b[0]));
- }
- else{
- SortedFlights= Object.entries(selectedFligts);
- }
- for (const [key,value] of SortedFlights) {
- console.log(`{ Destination: '${key}', Status: '${Status}' }`)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement