Q:

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

0

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

All Answers

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

const compose = (...fns) => fns.reduce((f, g) => (...args) => f(g(...args)));
const add5 = x => x + 5;
const multiply = (x, y) => x * y;
const multiplyAndAdd5 = compose(
  add5,
  multiply
);
console.log(multiplyAndAdd5(5, 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