CodeAgeBy Sitezack
Modern JavaScript for ProsES6+ and async0 XP
Chapter progress0/6

Lesson 3 of 6

map, filter, reduce

Array methods replace most loops: filter keeps, map transforms, reduce aggregates.

They chain: scores.filter(s => s >= 10).map(s => s * 2) — reads like a sentence.

const doubled = [1, 2].map((n) => n * 2);
const sum = [1, 2, 3].reduce((acc, n) => acc + n, 0);

🎯 Exercise

With const scores = [12, 5, 8, 20]: 1) write into #list the scores greater than or equal to 10, doubled, joined by a comma (result: 24,40) via filter + map + join; 2) write into #total the sum of all scores via reduce (result: 45).

PRO lesson

This advanced chapter is part of CodeAge PRO. Unlock it to keep your adventure going.

Discover PRO