Explaining this concept might be a bit complex, but here is the official breakdown:
mostPopularDays: This function identifies which day of the week had the highest number of visitors at the pet store. If multiple days tie for the highest traffic, an array containing those days should be returned in any order. In case of null or an empty input array, the function should return null. The input consists of Weekday objects created using the prototype function outlined in petstore.js. The desired output is a string with the name of the most popular day if only one stands out, and an array of names (in string format) for multiple top days.
The current version of the code snippet looks like this:
function mostPopularDays (week) {
var name,
dayInstance,
highestTrafficYet = -1;
for (var i = 0; i < week.length; ++i) {
dayInstance = week[i];
traffic = dayInstance.traffic;
if (highestTrafficYet < traffic) {
name = dayInstance.name;
highestTrafficYet = traffic;
}
}
return name;
}
If there are multiple equally popular days, how can I modify the code to return an array instead?