Q:

Write a JavaScript program to perform left-to-right function composition

0

Write a JavaScript program to perform left-to-right function composition

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

const pipeFunctions = (...fns) => fns.reduce((f, g) => (...args) => g(f(...args)));
const add5 = x => x + 5;
const multiply = (x, y) => x * y;
const multiplyAndAdd5 = pipeFunctions(multiply, add5);

console.log(multiplyAndAdd5(5, 2));
console.log(multiplyAndAdd5(16, 2));

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now