Skip to content

Day 3: Functional Iteration (forEach, map, filter)

Master functional iteration: forEach for side effects, map for transformation, and filter for subset extraction.

const prices = [10, 25, 40, 100];
// map: creates a new array of same length with transformed values
const formatted = prices.map(p => `$${p.toFixed(2)}`);
// filter: creates a new array with items that pass condition
const affordable = prices.filter(p => p < 50);
// forEach: executes callback for each item
prices.forEach((p, idx) => console.log(`Item ${idx + 1}: $${p}`));
  1. Take an array of temperatures in Celsius and use map to convert them to Fahrenheit.
  2. Filter an array of scores to keep only passing grades (>= 70).