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

311
Views
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 answers
Answer question

0

Use

for(let i of range.flat())

Because the range is a 2d array.

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!