Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function fligthSchedule(input) {
- const flightList = input.shift();
- const changedStatuses = input.shift();
- const status = input.shift().join(' ');
- const flights = {};
- for (const flight of flightList) {
- const [flightNumber, ...rest] = flight.split(' ');
- const destination = rest.join(' ');
- flights[destination] = flightNumber;
- }
- for (const changeStatus of changedStatuses) {
- const [flightNumber, changedStatus] = changeStatus.split(' ');
- for (key in flights) {
- if (flightNumber === flights[key]) {
- flights[key] = changedStatus;
- break;
- }
- }
- }
- if (status === 'Cancelled') {
- for (const destination in flights) {
- if (flights[destination] === 'Cancelled') {
- console.log(
- `{ Destination: '${destination}', Status: '${flights[destination]}' }`
- );
- }
- }
- } else {
- for (const destination in flights) {
- if (flights[destination] !== 'Cancelled') {
- flights[destination] = 'Ready to fly';
- console.log(
- `{ Destination: '${destination}', Status: '${flights[destination]}' }`
- );
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement