This section is aimed at refreshing our knowledge on the map, filter, and reduce functions.
Usually, common language functions need to be extremely performant, which is a topic that spans beyond this book. Avoid reimplementing what is in the language already. Some of the examples in this chapter are here only for learning purposes.
reduce is most likely often neglected, hence, we will focus on it. Usually, reduce (as the name suggests) is used to reduce a collection in size to a smaller one, or even a single variable.
Here is the reduce function declaration:
reduce(callback, [initialValue])
The callback takes four arguments: previousValue, currentValue, index, and array.
To quickly remind you how the reduce function works, let's look at the following example:
const sumArrayElements = arr => arr.reduce((acc, elem) => acc+elem, 0);
console...