There is a code, it only works when you specify static data in var = mass []. But my value is generated by random numbers and at the same time the array itself outputs a from min / max value - NaN
How to fix?
var mass = []; var min = mass[0]; var max = mass[0]; for (i = 0; i < 20; i++) { mass[i] = Math.round(Math.random() * 100); } for (j = 0; j < mass.length; j++) { max = Math.max(max, mass[j]); min = Math.min(min, mass[j]); if (max < mass[j]) { max = mass[j]; } } console.log(mass, min, max);
min,maxon the first iteration? - MedvedevDev