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

306
Vistas
Google Scripts - SWITCH statement doesn't work with range

I'm working on a simple function that should return the quantity of specific elements in a passed range. I would like to use SWITCH statement but for some reason it doesn't work as I would expect:

function groupResult(range) {
  const resultsQuantity = {
    na: 0,
    fail: 0,
    pass: 0,
    empty: 0
  }
  for(let i of range) {
    switch(i){
      case 'N/A':
        resultsQuantity.na++;
        break;
      case "FAIL":
        resultsQuantity.fail++;
        break;
      case "PASS":
        resultsQuantity.pass++;
        break;
      default:
        resultsQuantity.empty++
    }
  }
  return resultsQuantity.na;
}

the function call in the spreadsheet looks like follows: call of the function in the spreadsheet

but as result I get "0" instead of expected "2"

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Use

for(let i of range.flat())

Because the range is a 2d array.

about 4 years ago · Juan Pablo Isaza Denunciar
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