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.
More Related Contents:
- What is ‘Currying’?
- Javascript equivalent of Python’s zip function
- map function for objects (instead of arrays)
- Does JavaScript have a method like “range()” to generate a range within the supplied bounds?
- How do I replace while loops with a functional programming alternative without tail call optimization?
- How to call reduce on an array of objects to sum their properties?
- Uncaught TypeError: Illegal invocation in JavaScript
- Why is immutability so important (or needed) in JavaScript?
- How to adapt trampolines to Continuation Passing Style?
- Is performing a mapping operation without using returned value an antipattern?
- Merge two arrays with alternating values
- RxJS Promise Composition (passing data)
- How to chain map and filter functions in the correct order
- How can I pre-set arguments in JavaScript function call? (Partial Function Application)
- Why are Promises Monads?
- Difference between declarative and imperative in React.js?
- What is context in _.each(list, iterator, [context])?
- Why no Array.prototype.flatMap in javascript?
- What is the in-place alternative to Array.prototype.filter()
- What object javascript function is bound to (what is its “this”)?
- Functional approach to basic array construction
- Get a function’s arity
- Split JavaScript array in chunks using Lodash
- Is it good to call subscribe inside subscribe?
- Currying a function that takes infinite arguments
- Why can I not pass a function call (rather than a function reference or an anonymous function) to setTimeout()?
- functional way to iterate over range (ES6/7) [duplicate]
- whats the difference between function foo(){} and foo = function(){}? [duplicate]
- How do I make a callable JS object with an arbitrary prototype? [duplicate]
- Explain bindbind() function