Notice that the reduce(..) looping happens each time the final composed(..) function is run, and that each intermediate result(..) is passed along to the next iteration as the input to the next call.
and the code snippet in question:
function compose(...fns) {
return function composed(result){
return fns.reverse().reduce( function reducer(result,fn){
return fn( result );
}, result );
};
}
The result was passed as the initial value of reduction, and will accumulate the result of every iteration. It could be a function, but there is no sign that it had been executed. So I think the result(..) in the text should be result.
Ch4, line 317:
and the code snippet in question:
The
result
was passed as the initial value of reduction, and will accumulate the result of every iteration. It could be a function, but there is no sign that it had been executed. So I think theresult(..)
in the text should beresult
.