Skip to content

Instantly share code, notes, and snippets.

@aromanyuk
Created May 23, 2018 09:11
Show Gist options
  • Save aromanyuk/48fb3a4a5fee2a9fef1cb47cf90af34b to your computer and use it in GitHub Desktop.
Save aromanyuk/48fb3a4a5fee2a9fef1cb47cf90af34b to your computer and use it in GitHub Desktop.
function calc({
balance,
months,
percent,
cashbackPercent,
earnings,
spendings
}){
let totalIncome = 0;
let credit = 0;
for(let i = 0; i < months; i++) {
let income = Math.round(balance * percent/100 /12);
let cashback = Math.round(spendings * cashbackPercent / 100);
balance += income + cashback;
console.log("Balance: ", balance, ", Income: ", income, ", cashback: ", cashback);
balance += earnings - credit;
credit = spendings;
totalIncome += income + cashback;
}
console.log("Total Income: ", totalIncome);
}
calc({
balance: 10000,
months: 12,
percent: 10,
cashbackPercent: 1,
earnings: 10000,
spendings: 5000
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment