reduce, some/every, find — simple patterns
Learn reduce for totals, some/every for boolean checks, and find to get the first matching item.
Intro to reduce & friends
Goal: Turn many values into one with reduce, check arrays with some/every, and get the first match with find.
- reduce: totals
- some/every: quick checks
- find: first match

reduce sum
reduce takes a callback and an initial value. Return the next accumulator each step.
// reduce: sum numbers with an initial value
const prices = [4, 6, 3];
const total = prices.reduce(function (acc, n) {
// Add current number to the accumulator
return acc + n;
}, 0);
console.log("Total:", total);

All lessons in this course
- map & filter — essentials
- reduce, some/every, find — simple patterns