javascript match two arrays then display max value -
i trying match 2 values in 2 arrays
var months ['jan', 'feb', 'march']; var nodays ['31', '28', '31'];
then want fin months maximum number , return them such
"both jan , march have total of 31 days"
any suggestions please
well, problem solved simple algorithm:
var months = ['jan', 'feb', 'march']; var nodays = [31, 28, 31]; var maxdays = 0; var longestmonths = []; (var = 0; i<math.min(months.length, nodays.length);i++){ if(nodays[i]>maxdays){ maxdays = nodays[i]; longestmonths = [months[i]]; }else if(nodays[i]==maxdays) longestmonths.push(months[i]); }
after executing code, maxdays 31
and longestmonths ['jan', 'march']
Comments
Post a Comment