What does the following composition of higher-order functions do?
const result = [1, 2, 3, 4, 5]
.filter(n => n % 2 === 0)
.map(n => n * n)
.reduce((sum, n) => sum + n, 0);
This code sums the squares of all even numbers in the array. It demonstrates function composition with higher-order functions, processing data in a pipeline. First, filter() selects only even numbers [2, 4], then map() transforms each number to its square [4, 16], and finally reduce() sums these values to produce 20. This functional approach allows for a declarative, step-by-step data transformation that's readable and maintainable. Each function in the chain takes the output of the previous function as its input, enabling complex operations to be broken down into simple, composable pieces.