I'm trying to make a function that returns the highest value of the attribute of an object within an array, always return the initial value of the variable that I output in my function, please any suggestions. Thank you
var lunes = new Weekday("lunes", 5);
var martes = new Weekday("martes", 5);
var miercoles = new Weekday("miercoles", 15);
var jueves = new Weekday("jueves", 30);
var viernes = new Weekday("viernes", 50);
var week = [lunes,martes,miercoles,jueves,viernes] ;
var result = mostPopularDays(week);
console.log(result);
function Weekday (name, traffic) {
this.name = name;
this.traffic = traffic;
}
function mostPopularDays(week) {
var masPublico = 0;
for(var i=0; i <= week[i] ; i++){
if(week[i].traffic < masPublico ){
masPublico = week[i].traffic;
}
}
return masPublico;
}