Overview
Implement pipe(fns) that returns a function composing all functions left-to-right.
Examples
const transform = pipe([x => x + 1, x => x * 2]); transform(5); // 12
Solution
Reveal solution
function pipe(fns) {
return function(input) {
return fns.reduce((acc, fn) => fn(acc), input);
};
}pipe.js
Pipe
easycodingJavaScriptFunctions
Overview
Implement pipe(fns) that returns a function composing all functions left-to-right.
Examples
const transform = pipe([x => x + 1, x => x * 2]); transform(5); // 12
Solution
Reveal solution
function pipe(fns) {
return function(input) {
return fns.reduce((acc, fn) => fn(acc), input);
};
}NameTopicDifficulty
103 of 103 problems