Hint
Chain functions: output of one becomes input of next — compose=right-to-left, pipe=left-to-right
Function composition combines multiple functions where the output of one becomes the input of the next, building complex operations from simple pieces.
// compose — right to left (mathematical convention)
const compose = (...fns) => x => fns.reduceRight((v, f) => f(v), x);
// pipe — left to right (more readable)
const pipe = (...fns) => x => fns.reduce((v, f) => f(v), x);
const trim = str => str.trim();
const lowercase = str => str.toLowerCase();
const addBang = str => str + '!';
// compose: addBang(lowercase(trim(x)))
const processC = compose(addBang, lowercase, trim);
// pipe: trim → lowercase → addBang
const processP = pipe(trim, lowercase, addBang);
processP(' Hello World '); // 'hello world!'
processC(' Hello World '); // 'hello world!'
// Without composition (harder to read as chain grows)
const manual = str => addBang(lowercase(trim(str)));