Senior Software Engineer
Average MPG Function Implementation
Write a function that takes a collection of Cars with properties (Make, Model, MPG) and returns the average MPG for a specified Make. Input example: Make Model MPG Honda Accord 25.0 Honda Civic 28.0 Nissan Altima 24.5 Honda CRV 22.7 Toyota Tundra 19.1 Output example: Average MPG for Honda: [averageValue]
function gettingAverage(list, whatMake) {
count = 0;
sum = 0;
list.forEach(e => {
if (whatMake.toUpper() === e.make.toUpper()) {
sum += e.miles;
count += 1;
}
});
if (count == 0) return 0;
return sum / count;
}
const list = [{miles: 12, make: "toy", Model: ""}, {miles: 13, make: "toy"}, {miles: 14, make: "other"}];
const whatMake = "toy";
console.log(gettingAverage(list, whatMake));This question was asked in
CarMax Senior Software Engineer Interview Experience
The CarMax interview process featured a comprehensive set of questions primarily focused on JavaScript, TypeScript, React, and .NET technologies. The interview included one round that asked a variety of technical questions, including questions on variable declarations, dependency injection, and practical coding tasks. Overall, the difficulty level was medium, with a good blend of theoretical knowledge and practical application expected from candidates.