- 1
how tow write a function max withe reduce
2 Answers
0
Reduce applies a function that takes two values and returns one.
This is applied iteratively to all pairs of array[i], arrai[i+1], until only one value is left.
If you want to add up all the numbers, you'd write a function that adds two numbers.
So what would you need to return from the function, if you wanted the biggest value in the end? What would you have to do with each pair?
0
var max = arr => arr.reduce((a,v) => a<v ? v : a);