0Pricing
JavaScript Academy · Lesson

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, some/every, find — simple patterns — illustration 1

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);
reduce, some/every, find — simple patterns — illustration 2

All lessons in this course

  1. map & filter — essentials
  2. reduce, some/every, find — simple patterns
← Back to JavaScript Academy