Skip to content

Instantly share code, notes, and snippets.

@parasdaryanani
Last active March 18, 2021 11:28
Show Gist options
  • Save parasdaryanani/f646f3389489c2b452d2e38549df161e to your computer and use it in GitHub Desktop.
Save parasdaryanani/f646f3389489c2b452d2e38549df161e to your computer and use it in GitHub Desktop.
Calculate Profit using a generic pipe function
const pipe = (...fns) => arg => fns.reduce((value, fn) => fn(value), arg);
const calculateProfit = pipe(
// Deduct EU VAT (0.20)
value => value * (1 - 0.2),
// Deduct corporation tax (0.20)
value => value * (1 - 0.2),
// Add external contributions
value => value + 2500,
// Split with 0 co-founders
value => value / 3,
);
// console.log(calculateProfit(1000))
// 1046.67
export default calculateProfit;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment