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 composeRight = (...fns) => fns.reduce((f, g) => (...args) => g(f(...args)));
const add = (x, y) => x + y;
const square = x => x * x;
const addAndSquare = composeRight(add, square);

console.log(addAndSquare(1, 2));
console.log(addAndSquare(3, 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