Lesson 22 — Compose & pipe (expert)
Build pipelines from small functions
pipe(f, g, h) creates a function that sends a value through f, then g, then h — each one gets the previous result. compose is the same but right-to-left. You can build pipe with reduce: start with the input value and apply each function in turn.
const shout = (s) => s.toUpperCase();
const excite = (s) => s + "!";
console.log(excite(shout("hi"))); // HI! — pipe(shout, excite)("hi")
Why it matters: data cleaning and transformation code becomes a readable list of steps.
Finish pipe so pipe(inc, double)(3) prints 8 and pipe(double, inc)(3) prints 7.
Run your code — when the output matches the task, you will see a green check. Then mark the lesson complete.
A quick 3-question quiz on this lesson — instant feedback.
Ready for more? Optional paid resources that pick up where this lesson leaves off.
Some links on this page are affiliate links: we may earn a commission at no extra cost to you. As an Amazon Associate I earn from qualifying purchases.
Project-based JavaScript Intermediate courses if you want a structured paid path after the free lessons. Wait for a sale — prices drop often.
Browse on Udemy →Search Amazon for JavaScript Intermediate books — check the publication year so the examples match current versions.
Search Amazon →