DEV Community

Discussion on: Map, Filter and Reduce explained.

Collapse
 
kongfuboy123 profile image
打coding的奥特曼

Why not complete them in a line ?
const output=array.map(element=>element*2);
const output=array.filter(element=>element%2);
const output=array.reduce((acc,curr)=>acc+curr,0);

Collapse
 
namitmalasi profile image
namitmalasi

yes,it could have been done in one line but as a beginner someone might get confused, who is not familiar with this syntax.