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


In essence, this works:

  [1, 2, 3]. Reduce (function (A, B) {return mathematics. Max (A, B);}); = & Gt; 3  

But this is not:

  [1, 2, 3] .reduce (Math. Max); = & Gt; Nan  

Pure Puzzle.

It's in Firefox 3.5.9, which I think is using FWID.

Math.max should be used as a high-order function Could. The problem is .readuce will call the function with 4 arguments:

  Math.max (accumulator, value, index, d_re)  
< P> Here is an array, so Math.max gives NaN I do not think the last two arguments are an easy way to quit.


Comments