我有资产(说车辆),今年价值1000 ......
var assetCurrentBookValue = 1000
车辆将在5年内贬值......这意味着该价值将在未来5年内变为0 ......
var assetLife = 5
年度折旧成为......
var assetYearlyDepreciation = assetCurrentBookValue / assetLife
我需要计算每年折旧之后的年度价值......
year assetYearlyDepreciation assetBookVaue
2016 200 1000
2017 200 800
2018 200 600
2019 200 400
2020 200 200
2021 200 0
我需要像这样转换成数组......
[
[2016,1000],
[2017,800],
[2018,600],
[2019,400],
[2020,200],
[2021,0]
]
这是我的解决方法......
var index = Array.from(Array(assetLife).keys());
var thisYear = new Date().getFullYear()
var assetYearlyBookValue = [[thisYear,assetCurrentBookValue]]
index.forEach((o) => {
assetYearlyBookValue.push([o + thisYear + 1, assetCurrentBookValue - assetYearlyDepreciation])
});
但是我得到了..
[
[2016,1000],
[2017,800],
[2018,800],
[2019,800],
[2020,800],
[2021,800]
]
任何帮助将不胜感激...谢谢Youu ..
答案 0 :(得分:2)
修改assetCurrentBookValue - assetYearlyDepreciation
和new Date().getFullYear()
的结果并将其存储到变量中,以便获得不断变化的结果:
var index = Array.from(Array(assetEconomicLife).keys());
var thisYear = new Date().getFullYear()
var assetYearlyBookValue = [[thisYear,assetCurrentBookValue]]
var lastRes = assetCurrentBookValue
index.forEach((o) => {
lastRes -= assetYearlyDepreciation
assetYearlyBookValue.push([o + (++thisYear), lastRes])
});