'composes an array of functions into a function that passes a value through a pipeline of functions
Does anyone know how to do this ? #compose pipeline
Q) composes an array of functions into a function that passes a value through a pipeline of functions.
We need to create compose () as follows !
function compose(funcs) {
}
Example 1
javascript
const pipeline = [
(num) => num - 1,
(num) => num * 10,
(num) => `${ num } as a string`
];
const composed = compose(pipeline);
The output will be :--->
composed(4); // => `30 as a string`
Example 2
javascript
const pipeline = [
(str) => str.length,
(length) => length * 100,
(num) => num + 5
];
const composed = compose(pipeline);
composed('cat'); // => 305
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
