How to use Math.max, etc. as higher-order functions

Math.max can be used as a higher-order function. The problem is .reduce will call the function with 4 arguments:

Math.max(accumulator, value, index, the_array)

here is the_array is an array, so Math.max returns NaN. I don’t think there’s simpler way to discard the last 2 arguments.

Leave a Comment