Skip to content

Instantly share code, notes, and snippets.

@parasdaryanani
Created March 18, 2021 16:32
Show Gist options
  • Save parasdaryanani/b738d2dd912d932f9a429e4e70c8237b to your computer and use it in GitHub Desktop.
Save parasdaryanani/b738d2dd912d932f9a429e4e70c8237b to your computer and use it in GitHub Desktop.
Calculate profit through chain methods
export default class Calculator {
constructor() {
this.value = 0;
}
revenue(value) {
this.value = value;
return this;
}
deductTax(percentage) {
this.value = this.value - (percentage * this.value) / 100;
return this;
}
// EU VAT convenience method
deductVAT(percentage = 20) {
return this.deductTax(percentage);
}
// UK Corporation tax convenience method
deductCorpTax(percentage = 20) {
return this.deductTax(percentage);
}
deductCost(value) {
this.value = this.value - value;
return this;
}
}
// const a = new Calculator()
// .revenue(1250)
// .deductVAT()
// .deductCorpTax();
// console.log(a.value);
// Console Output
// 800
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment