Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

172
Visualizações
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 Respostas
Responde à pergunta

0

Try

await getMileagePrice(arrayOfValues,productName)
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda