frontend-challenges
frontend-challenges copied to clipboard
471 - Pipe - javascript
index.js
/**
* Creates a function that pipes values through a sequence of functions.
* @param {Function[]} functions - array of unary functions
* @returns {Function} composed function
*/
export function pipe(functions) {
// TODO: Implement me
return (initialArg) => {
return functions.reduce((acc, current) => {
acc = current(acc);
return acc;
}, initialArg)
};
}