22 - Exercise 6-Get Max

For the first part I just did the following and it recognized = [] as undefined and was able to properly assign the largest value. If this fails under some condition that the longer code in the video shows, please let me know! edit* The check for an empty array with if statement appears necessary using the reduce method, but not the for loop below.

const numbers = [7,1,6,5];

const max = getMax(numbers);

console.log(max);

function getMax(array) {
    let largest = array[0];
    for (let num of array)
        if (num > largest) 
            largest = num;
    return largest;