16
Replace Loop with Pipeline
Goal
Filter / map / reduce expresses the transformation as a sequence of named operations; intent jumps off the page.
Before the refactoring
const seniors = [];
for (const u of users) {
if (u.age >= 65) seniors.push(u.name);
}After the refactoringconst seniors = users
.filter(u => u.age >= 65)
.map(u => u.name);Savings
Off-by-one and accumulator bugs vanish; each step is independently testable.
Note
Pipelines add a tiny per-element function-call overhead — usually negligible, but profile if you're in a hot path.