let numbers = [10, 20, 30, 40];
console.log(numbers.map(n => n * 2)); // [20, 40, 60, 80]
console.log(numbers.filter(n => n > 20)); // [30, 40]
console.log(numbers.reduce((a, b) => a + b, 0)); // 100
Explanation:
map()
→ transforms values.filter()
→ selects values that match condition.reduce()
→ accumulates into one value.
Leave a Reply