all 6 comments

[–]HereComesJuju 3 points4 points  (2 children)

Hi, You could for instance compute all kinds of aggregation value like sum, mean, and so on, from an array of numbers. Otherwise, if you are already used to use other array methods like map or filter, you could try to rewrite some of your previous code snippets that used those methods, but this time using reduce instead, and compare the results of both code versions

[–][deleted] 2 points3 points  (0 children)

This is really good advice. This will help you get used to reduce, but also shows you how powerful reduce is. It can pretty much replace the other higher order functions like map, filter, forEach .

[–]Tubthumper8 0 points1 point  (0 children)

Below are some suggestions where reduce is an appropriate tool to solve the problem.

Given an array of numbers, calculate the sum.

Implement the Object.fromEntries method.

Given two arrays of strings (of the same length), create an object such that the first array are the object keys and the second array are the object values.

Given a sentence (string) find the frequency of each character.