javascript / intermediate
Snippet
Declarative Data Transformation
Chaining higher-order functions like filter and map allows for processing collections in a clean, readable, and declarative way.
snippet.js
1
2
3
4
const nums = [1, 2, 3, 4, 5];const result = nums.filter(n => n > 2).map(n => n * 2);
Breakdown
1
.filter(n => n > 2)
Creates a new array containing only elements greater than 2.
2
.map(n => n * 2)
Transforms each remaining element by doubling its value.