#### [SOLVED] Hello how can i find the biggest average passangers in this array and the company with it?

``````function solve(input) {
let avioCompanies = Number(input.shift())
for (let i = 1; i <= avioCompanies; i++) {
var command = input.shift()
let passangers = Number(input.shift())
let avg = 0
let count2 = 0
while (passangers !== "Finish") {
avg += passangers
count2++
passangers = input.shift()
}
avg /= count2
console.log(`\${command}: \${Math.floor(avg)} passengers.`);

}
console.log(``);
}
solve([2, "Qatar Airways", 95, 231, 323, "Finish", "LOT", 76, 89, 55, "Finish"])``````

#### @DavidXYZ 2020-08-01 13:47:54

You just need to keep track of the max while you are calculating the averages:

``````function findMaxAverage(input) {
let numCompanies = Number(input.shift());
let maxAvg = 0; maxCompany = "";
for (let i = 0; i < numCompanies; i++) {
let company = input.shift();
let passengers = Number(input.shift());
let total = 0;
let count = 0;
while (passengers !== "Finish") {
total += passengers;
count++;
passengers = input.shift();
}
let avg = total / count;
console.log(`\${company}: \${Math.floor(avg)} passengers.`);
if (avg > maxAvg) {
maxAvg = avg;
maxCompany = company;
}

}
console.log(`----------`);
console.log(`Maximum: \${maxCompany} with an average of \${Math.floor(maxAvg)} passengers.`);
}

findMaxAverage([2, "Qatar Airways", 95, 231, 323, "Finish", "LOT", 76, 89, 55, "Finish"]);
``````

### [SOLVED] How can I remove a specific item from an array?

• 2011-04-23 22:17:18
• Walker
• 6974239 View
• 8528 Score
• Tags:   javascript arrays

### [SOLVED] How can I convert a string to boolean in JavaScript?

• 2008-11-05 00:13:08
• Kevin
• 2091374 View
• 2630 Score
• Tags:   javascript

### [SOLVED] How can I add new array elements at the beginning of an array in Javascript?

• 2011-11-10 00:35:22
• Moon
• 837135 View
• 1626 Score
• Tags:   javascript arrays

### [SOLVED] How can I change an element's class with JavaScript?

• 2008-10-12 20:06:43
• Nathan Smith
• 2628544 View
• 2818 Score