To accomplish our task, we create a function called findMax() and pass in our array.
Inside the body, we need to create a variable referencing our found maximum value. We set the variable max to the first element of our array. Since this it the first maximum existing. We didn’t check any other so far.
The next step is to loop over the array and check if the element we are currently looking at is greater than our current max value.
If so, replace it to the newly found maximum element of array.
Once, we are done with iterating, comparing, and adding, just return the found maximum and print it to the console, and you are done!
Follow me on Instagram and don’t miss the latest Challenge!