CarMax
CarMax

Senior Software Engineer

Average MPG Function Implementation

Medium
Round 1CodingCandidate Not Selected

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]

Code Snippets
javascript
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.

AI Powered

Share Your Story

Share your interview in your own words — our AI handles the rest. Hardly takes 2 minutes.

Take Mock Interview

Prepare better with expert feedback

Want to Connect 1:1?

Connect with me 1:1 for career guidance, resume reviews, interviews, and more.

Show Your Love!

Connect with us on social media

Average MPG Function Implementation | CarMax Interview Question | InterviewRecap | InterviewRecap