As a Front-end Engineer: 10 Secrets about “[].reduce” You Must Know About
My good friend, as a front-end developer, you must use the reduce
function a lot, it is a powerful and useful array API, but today I want to share with you 10 advanced tricks and tips about it, come on!
1. As an adder and accumulator
Using “reduce”, we can easily implement the function of adding or accumulating several numbers.
2. Calculate the max and min value of an array
How many ways do you get the maximum or minimum value of an array?
1: Using Math.max and Math.min
We have to admit that using Math’s API is the easiest way.