So I need some help trying to understand this code. I know the objective here for this function to loop through this array and find the maximum value. However I'm confused with what exactly "array[0]" and "array[i]" is. Thanks in advance.
var max_value = function(array) {
var result = array[0];
for (var i = 0; i < array.length; i++) {
if (array[i] > result) {
result = array[i];
};
}
return result;
}
console.log(max_value([1, 50, 2]));
;after the closing}on the block attached to theif. You do want one on the closing}attached to the function expression. Using correct, consistent indentation can make errors like that clearer. The code works, because;where it shouldn't be is largely harmless (just an empty statement), and JavaScript has this horrible thing called Automatic Semicolon Insertion that will frequently (but not always) insert semicolons for you if you leave them off.