JavaScriptBeginner#arrays

Explain map, filter and reduce.

map transforms each element into a new array of the same length. filter keeps elements passing a predicate. reduce folds the array into a single accumulated value. All three are pure and do not mutate the source.

Example
const n = [1,2,3,4];
n.map(x => x*2);            // [2,4,6,8]
n.filter(x => x % 2 === 0); // [2,4]
n.reduce((s,x) => s + x, 0);// 10

Related Questions

1
JavaScriptBeginner#arrays

Difference between forEach and map?

Open
2
JavaScriptBeginner#arrays

Difference between slice and splice?

Open
3
JavaScriptBeginner#arrays

What do find, findIndex, some and every do?

Open