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

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

0

Use

for(let i of range.flat())

Because the range is a 2d array.

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