We are still cooking the magic in the way!
Problem
Traditional for loops to transform arrays are verbose and error-prone with manual index management.
Solution
Use Array.map() to transform arrays in a functional, declarative way.
Benefit
Reduces code by 60%, eliminates off-by-one errors, and makes intent clearer.
Code Example
// Instead of:
const doubled = [];
for (let i = 0; i < numbers.length; i++) {
doubled.push(numbers[i] * 2);
}
// Use:
const doubled = numbers.map(n => n * 2);