Day 3: Functional Iteration (forEach, map, filter)
Daily Objective
Section titled “Daily Objective”Master functional iteration: forEach for side effects, map for transformation, and filter for subset extraction.
1. Functional Trio
Section titled “1. Functional Trio”const prices = [10, 25, 40, 100];
// map: creates a new array of same length with transformed valuesconst formatted = prices.map(p => `$${p.toFixed(2)}`);
// filter: creates a new array with items that pass conditionconst affordable = prices.filter(p => p < 50);
// forEach: executes callback for each itemprices.forEach((p, idx) => console.log(`Item ${idx + 1}: $${p}`));Daily Hands-on Practice (70%)
Section titled “Daily Hands-on Practice (70%)”- Take an array of temperatures in Celsius and use
mapto convert them to Fahrenheit. - Filter an array of scores to keep only passing grades (
>= 70).