Programs & Examples
Arrow Functions · Study material
A pricing pipeline built from small arrows
Curried arrows (discount(25), addTax(18)) create configured functions that pipe combines into reusable pricing rules.
// Small arrow functions combined into a pricing pipeline
const pipe = (...fns) => (x) => fns.reduce((v, f) => f(v), x);
const discount = (pct) => (p) => p * (1 - pct / 100);
const addTax = (pct) => (p) => p * (1 + pct / 100);
const round2 = (p) => Math.round(p * 100) / 100;
const rupees = (p) => `₹${p.toFixed(2)}`;
const studentPrice = pipe(discount(25), addTax(18), round2, rupees);
const regularPrice = pipe(addTax(18), round2, rupees);
const courses = [{ name: "JavaScript", fee: 1999 }, { name: "Python", fee: 2499 }];
courses.forEach(({ name, fee }) => console.log(`${name.padEnd(11)} regular ${regularPrice(fee)} student ${studentPrice(fee)}`));
JavaScript regular ₹2358.82 student ₹1769.12 Python regular ₹2948.82 student ₹2211.61
Countdown with setTimeout
The timer example on the Introduction tab keeps this across repeated setTimeout calls simply by using an arrow function.