Skip to content

Day 4: reduce, find, some & every

Master the powerful reduce method to compute accumulators and check collection criteria with find, some, and every.

const numbers = [10, 20, 30, 40];
const total = numbers.reduce((acc, current) => acc + current, 0);
console.log(total); // 100
const users = ['Alice', 'Bob', 'Charlie'];
const charlie = users.find(u => u.startsWith('C')); // "Charlie"
const hasBob = users.some(u => u === 'Bob'); // true
const allLong = users.every(u => u.length >= 3); // true
  1. Use reduce to find the maximum number in an array.
  2. Calculate the average score from an array of numbers using reduce.