I was looking into how to find the min and max value in an array (without using Math) and I came across this code in a forum:
var array = [4, 2, 3, 4]
var min = arrayMin(array);
out.innerHTML = min;
function arrayMin(arr) {
var len = arr.length, min = Infinity;
while (len--) {
if (arr[len] < min) {
min = arr[len];
}
}
return min;
};
<p id="out"></p>
I can't really wrap my head around it and understand it fully, especially the infinity part. Could someone be so nice and explain it as simple as possible?