'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"
Solution 1:[1]
Use
for(let i of range.flat())
Because the range is a 2d array.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Fuad Hasan |
