1 回答
TA贡献1817条经验 获得超6个赞
我把一些东西放在一起。也许这可以帮助您入门。这个想法是 1) 设置一些基值 2) 将其放入您想要计算的 n 年循环中。3)以数组形式返回最终结果,以便您可以逐年查看
// Calculate the next year
const caclNextYear = (lastYear, fixedYearVal, profitability) => {
const nextYr = lastYear + fixedYearVal;
const percentSecondYear = (profitability / 100) * nextYr;
const finalYr = percentSecondYear + nextYr;
return finalYr;
};
// Calc years by number of years
const estimateByYears = (years) => {
const contributions = 536.06;
const profitability = 4.27;
const fixedYearVal = 536.06 * 12; // 6.432,72
const profitabilityVal = (profitability / 100) * fixedYearVal;
const fixedYearprofitability = fixedYearVal + profitabilityVal;
const yearByYear = [fixedYearprofitability];
for (let i = 1; i < years; i++) {
let lastYr = yearByYear[yearByYear.length - 1];
yearByYear.push(caclNextYear(lastYr, fixedYearVal, profitability));
}
return yearByYear;
};
// Call
const yearByYear = estimateByYears(5);
// yearByYear : [6707.397144, 13701.200146048799, 20993.63853628508, 28597.46404578445, 36525.97290453945
console.log('yearByYear', yearByYear);
添加回答
举报