This content originally appeared on DEV Community and was authored by Wendley Paulo de França
Create a generic pipe function.
const pipe = (...fns) => (arg) => fns.reduce((value, fn) => fn(value), arg)
Use it to create a reusable pipe.
const calculateProfit = pipe(
// Deduct VAT (8%)
value => value * (1 - 0.08),
// Deduct tax (15%)
value => value * (1 - 0.15),
// Add external contributions
value => value + 2500,
// Split with co-founder (3 co-founders)
value => value / 3
);
Use the pipe to perform calculation
const revenue = 50_000;
const profit = calculateProfit(revenue);
This content originally appeared on DEV Community and was authored by Wendley Paulo de França

Wendley Paulo de França | Sciencx (2021-10-06T02:16:56+00:00) Creating A Reusable Pipe Using JavaScript. Retrieved from https://www.scien.cx/2021/10/06/creating-a-reusable-pipe-using-javascript/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.