Day 4: reduce, find, some & every
Daily Objective
Section titled “Daily Objective”Master the powerful reduce method to compute accumulators and check collection criteria with find, some, and every.
1. Array Reduction: reduce
Section titled “1. Array Reduction: reduce”const numbers = [10, 20, 30, 40];const total = numbers.reduce((acc, current) => acc + current, 0);console.log(total); // 1002. Searching & Checking
Section titled “2. Searching & Checking”const users = ['Alice', 'Bob', 'Charlie'];const charlie = users.find(u => u.startsWith('C')); // "Charlie"const hasBob = users.some(u => u === 'Bob'); // trueconst allLong = users.every(u => u.length >= 3); // trueDaily Hands-on Practice (70%)
Section titled “Daily Hands-on Practice (70%)”- Use
reduceto find the maximum number in an array. - Calculate the average score from an array of numbers using
reduce.