Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

182
Views
How to reuse this code and make it more dynamic

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();
}

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Try

await getMileagePrice(arrayOfValues,productName)
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!