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

171
Views
Cómo reutilizar este código y hacerlo más dinámico

Soy nuevo en Javascript y, aunque puedo arreglármelas, necesito ser más inteligente.

Tengo este código que se repite unas 7 veces, lo único que cambia en el código es getMileagePrice, Mileage y getMileageRate, todo lo demás es exactamente igual.

Llamo a esta función usando el comando 'google.script.run' de Google Apps Scripts. google.script.run.withSuccessHandler(getMileagePrice).getFeesArray();

¿Cómo puedo reutilizar esto para usar 6 líneas de código en lugar de 42 líneas de código (7 funciones x 6 líneas de código)?

 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

Probar

 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!