Answers for "Create Composite Functions"

0

Create Composite Functions

// create composite functions
const composite = (...args) => (initialArg) => args.reduceRight((acc, fn) => fn(acc), initialArg);

const sqrt = (value) => Math.sqrt(value);
const double = (value) => 2 * value;

const newFunc = composite(sqrt, double);

// ( 32 * 2 ) ** 0.5
let result = newFunc(32);
console.log(result); // 8
Posted by: Guest on June-26-2021

Code answers related to "Create Composite Functions"

Code answers related to "Javascript"

Browse Popular Code Answers by Language