freecoding.school100% FREE · NO SIGNUP
Closure CavesISSUE #21 of 61

array methods · map · filter · reduce

LambdaVSThe Mutator
Lambda saysmap transforms, filter selects, reduce accumulates — the trio of functional array methods.

map returns a new array with each item transformed; filter returns the items that pass a test; reduce folds the array into a single value (sum, object, anything). All three are non-mutating and chainable, replacing most manual loops with clear, declarative pipelines.

Power-ups you unlock

The Mutator attacks — common mistakes

Boss battleChain filter then map then reduce: keep evens, double them, sum the result.

Example code

<!doctype html><html><head><meta charset="utf-8"></head>
<body style="background:#06040d;color:#e6e0ff;font-family:monospace;padding:20px"><pre id="o"></pre>
<script>const r=[1,2,3,4,5,6].filter(n=>n%2===0).map(n=>n*2).reduce((a,b)=>a+b,0);
document.getElementById('o').textContent='result = '+r;</script></body></html>
▶ Open the interactive comic issue
‹ Array Methods · Slice · SpliceArray Methods · Find · FindIndex · Some · Every ›