I'm new to Javascript and although I can get by, I need to get smarter.
I have this code which is repeated about 7 times, the only thing that changes in the code is the getMileagePrice, Mileage and getMileageRate, everything else is exactly the same.
I call this function using the 'google.script.run' command from Google Apps Scripts. google.script.run.withSuccessHandler(getMileagePrice).getFeesArray();
How can I reuse this so I'm using 6 lines of code rather than 42 lines of code(7 functions x 6 lines of code).
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();
}
Try
await getMileagePrice(arrayOfValues,productName)