Find Maximum Number using reduce()
that takes an array of numbers as input, and returns the maximum number using the
Solution Walkthrough for Find Maximum Number using reduce()
Don't read this unless you've already solved the problem.
, as there is no maximum number to be found in an empty array.
to iterate over the array and find the maximum number. The initial value of the accumulator is set to the first element of the array
. We then compare each element of the array to the current maximum using
. If the current element is greater than the current maximum, we return the current element, otherwise we return the current maximum.