Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

393
Vistas
Why does adding an else statement slow my code so much?

I feel like there is perhaps an obvious answer. When I'm running this code:

function searchQuery() {
  var compiledParticipantsSheet = spreadSheet.getSheetByName('Participants');
  var participantsSheetLr = compiledParticipantsSheet.getLastRow();
  var participantsSheetLc = compiledParticipantsSheet.getLastColumn();
  var querySheet = spreadSheet.getSheetByName('Query');
  var querySheetLr = querySheet.getLastRow();
  var querySheetLc = querySheet.getLastColumn();
  var data = querySheet.getRange(3, 1, querySheetLr, querySheetLc).getValues();
  for (j = 2; j <= participantsSheetLr; ++j) {
    var val = compiledParticipantsSheet.getRange(j, 2, 1, 1).getValue();
    console.log('Searching Query sheet for row ' + j + ' -- ' + val)
    for (i = 0; i < data.length; ++i) {
      if (data[i][4] == val) {
        var foundData = (data[i][20]);
        console.log('------ Found email in query row ' + (i + 3) + ' = ' + foundData);
        compiledParticipantsSheet.getRange(j, 11, 1, 1).setValue(foundData);
      }else{
       compiledParticipantsSheet.getRange(j, 11, 1, 1).setValue('Participant not found');
      }
    }
  }
}

It runs painfully slow, but if I remove the one else statement at the end it runs super fast! Is that reasonable? Am I missing something? Thanks!

about 4 years ago · Santiago Gelvez
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda