I try to get some details from the code below:
const upperCase = str => str.toUpperCase();
const exclaim = str => `${str}!`;
const repeat = str => `${str} `.repeat(3);
const compose = (...fns) => x => fns.reduceRight((acc, fn) => fn(acc), x);
const withСompose = compose(
repeat,
exclaim,
upperCase
);
console.log(withСompose("hello"));
Questions:
- How
x
from=> x =>
, go insteadx
fromfn(acc), x);
? - Why
const compose = (...fns) => x => fns.reduceRight((acc, fn) => fn(acc), x);
does not work in this wayconst compose = (...fns) => fns.reduceRight((acc, fn) => fn(acc));
?