Skip to content

Instantly share code, notes, and snippets.

@zzdjk6
Created November 7, 2019 21:14
Show Gist options
  • Save zzdjk6/d78e7aa3ec96d707a5df6777222230d6 to your computer and use it in GitHub Desktop.
Save zzdjk6/d78e7aa3ec96d707a5df6777222230d6 to your computer and use it in GitHub Desktop.
const discount1 = (price, discount) => {
const final = price * (1 - discount);
console.log(`V1 -- Original Price: ${price}, Discount: ${discount}, Final Price: ${final}`);
}
discount1(500, 0.5);
discount1(400, 0.5);
discount1(300, 0.5);
const halfPrice1 = price => discount1(price, 0.5);
halfPrice1(500);
halfPrice1(400);
halfPrice1(300);
const discount2 = discount => price => {
const final = price * (1 - discount);
console.log(`V2 -- Original Price: ${price}, Discount: ${discount}, Final Price: ${final}`);
}
const halfPrice2 = discount2(0.5);
// const halfPrice2 = price => discount2(0.5)(price);
halfPrice2(500);
halfPrice2(400);
halfPrice2(300);
@zzdjk6
Copy link
Author

zzdjk6 commented Nov 7, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment