Answered step by step
Verified Expert Solution
Question
1 Approved Answer
const cities = [ { name: 'Hilo', population: 46559, island: 'Hawaii' }, { name: 'Urban Honolulu', population: 351554, island: 'Oahu' }, { name: 'Kahului', population:
const cities = [ { name: 'Hilo', population: 46559, island: 'Hawaii' }, { name: 'Urban Honolulu', population: 351554, island: 'Oahu' }, { name: 'Kahului', population: 27938, island: 'Maui' }, { name: 'Kaneohe', population: 34509, island: 'Oahu' }, { name: 'Kapaa', population: 11516, island: 'Kauai' }, ... { name: 'Waipahu', population: 39927, island: 'Oahu' }, ];
averagePopulation(data) and biggestAndSmallest(data). Each function takes a parameter formatted like the cities variable above. averagePopulation returns the average population of all passed cities. biggestAndSmallest returns a string indicating the biggest and smallest cities by population.
For example
console.log(averagePopulation(cities, 'Oahu')); // prints: 20346.85714285714 console.log(biggestAndSmallest(cities, 'Oahu')); // prints: Biggest: Urban Honolulu; Smallest: Maunawili console.log(averagePopulation(cities, 'Maui')); // prints: 9390.4375 console.log(biggestAndSmallest(cities, 'Maui')); // prints: Biggest: Kahului; Smallest: Kualapuu
You cannot use loops. Instead, use Underscore. Hint: consider using the Underscore functions filter(), reduce(), max(), and min().
Another hint: the last line of your biggestAndSmallest function could look like this:
return `Biggest: ${biggest}; Smallest: ${smallest}`;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started