Differences with Reduce, Map and Filter in JS

Publication: 5 of March, 2020
Today we are going to review reduce, map and filter with Javascript.
All of these are array methods that test each element of the array, for example reduce, with reduce we execute a reducer function on each element of the array, resulting in a single output value, like this.

[0, 2, 5].reduce((x, y) => x + y);

//will return 7

With the Map method returns a new array with the results of calling a provided function on every element in the calling array, like this.

[0, 2, 5].map((x) => x + 5);

//will return [5, 7, 10]

With the Filter method returns a new array with the true for the elements that pass the test and false for the ones that don't, like this.

["luis", "antonio", "miguel", "andres"].map( x => x.length > 5);

//will return [false, true, true, true]

And there are many more objects to check one, see you in the next one.

Copyright Luis Gonzalez 2021