【发布时间】:2022-09-25 23:55:58
【问题描述】:
我是 Javascript 的新手,虽然我能过得去,但我需要变得更聪明。
我有这段代码重复了大约 7 次,代码中唯一变化的是getMileagePrice、Mileage 和getMileageRate,其他一切都完全相同。
我使用 Google Apps Scripts 中的 \'google.script.run\' 命令调用此函数。 google.script.run.withSuccessHandler(getMileagePrice).getFeesArray();
我怎样才能重用它,所以我使用 6 行代码而不是 42 行代码(7 个函数 x 6 行代码)。
function getMileagePrice(arrayOfValues) {
var productName = \'Mileage\';
var filteredArrayOfValues = arrayOfValues.filter(function(r) {
return r[0] === productName
});
getMileageRate = filteredArrayOfValues.reduce((amount, r) => amount + r[1], 0).toFixed(2)
combinePrices();
}
-
没有足够的细节来理解你的意思
标签: javascript google-apps-script web-applications