Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function flight(input) {
- let numberOfAirCompanies = Number(input[0]);
- let mostPassengersPerFlight = 0;
- let companyWinner = "";
- let index = 1;
- for (let i = 0; i < numberOfAirCompanies; i++) {
- let flightCounter = 0;
- let tempPassengers = 0;
- let averagePersonPerFlight = 0;
- let tempCompany = input[index];
- index++;
- let command = input[index];
- while (true) {
- if (command === "Finish") {
- break;
- } else {
- flightCounter++;
- tempPassengers += Number(input[index]);
- index++;
- command = input[index];
- }
- }
- index++;
- averagePersonPerFlight = Math.floor(tempPassengers / flightCounter);
- console.log(`${tempCompany}: ${averagePersonPerFlight} passengers.`);
- if (averagePersonPerFlight < mostPassengersPerFlight) {
- companyWinner = tempCompany;
- mostPassengersPerFlight = averagePersonPerFlight;
- }
- }
- console.log(`${companyWinner} has most passengers per flight: ${mostPassengersPerFlight}`);
- }
- flight(3,
- "WizzAir"
- 180,
- 230,
- 100,
- "Finish",
- "BulgariaAir"
- 50,
- 60,
- 90,
- "Finish",
- "Lufthansa",
- 260,
- 320,
- "Finish");
Advertisement
Add Comment
Please, Sign In to add comment