Member-only story

As a Front-end Engineer: 10 Secrets about “[].reduce” You Must Know About

10 Tricks About Reduce That Make You Write Less And Do More.

fatfish
4 min readApr 26, 2023
Photo by Timothy Meinberg on Unsplash

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.

2: Using reduce

Yes, you can achieve the same effect as Math’s API with just one line of code.

3. Format the search parameters

Getting the search parameters on the link is something we often have to deal with. How to parse them?

--

--

fatfish
fatfish

Written by fatfish

Hi friends, I am a front-end engineer from Alibaba, let’s code happily together.

Responses (1)

Write a response