Declarative Data Transformation
Transform data with map, filter, and reduce.
Declarative vs Imperative
Imperative code says HOW (loops, counters, mutation). Declarative code says WHAT. Array methods like map, filter, and reduce let you describe transformations without manual loops.
const nums = [1, 2, 3, 4];
const doubled = nums.map((n) => n * 2);
console.log(doubled); // [2, 4, 6, 8]map: Transform Each Element
map returns a new array of the same length with each element transformed by your function. The original is untouched.
const names = ["ada", "bob"];
const upper = names.map((n) => n.toUpperCase());
console.log(upper); // ["ADA", "BOB"]
console.log(names); // unchangedAll lessons in this course
- Pure Functions and Side Effects
- Declarative Data Transformation
- Avoiding Mutation
- Point-Free Style