从下面的回复中,我如何动态计算总费率?
[ { "name": "所得税", “率”:20 }, { “名称”:“销售税”, “率”:8 }, { "name": "房产税", “率”:2 }, { "name": "企业税", “率”:15 }, { “名称”:“消费税”, “率”:5 } ]
我已尝试添加每个费率值,但我正在寻找明智的答案?
给你:
* def total = 0
* def response = [ { "name": "Income Tax", "rate": 20 }, { "name": "Sales Tax", "rate": 8 }, { "name": "Property Tax", "rate": 2 }, { "name": "Corporate Tax", "rate": 15 }, { "name": "Excise Tax", "rate": 5 } ]
* response.forEach(x => total = total + x.rate)
* print total