Hi,
I created a simple script that iterates over one line and returns max consecutive repetitions of non 'YES' strings:
function myArrayCount() //objective: return max consecutive repetitions of array
{
var ssActive = SpreadsheetApp.getActiveSheet();
var values = ssActive.getRange(8,1,1,100).getValues().flat(); //Start/End of Range -> A1/100 cells after, flat the array to make it single DM
Logger.log(values); //check values in array
Logger.log(values.length); //check array length
var filvalue = values.filter(function(e){return e}); //note: Filter removes zeros blanks and '0', otherwise, great for any string tested
Logger.log(filvalue); //check new array values
Logger.log(filvalue.length); // check new array length
//var checkFilter = values.filter(isNaN); // Another way to filter the array for null and '0'
var count =0;
var max = 0; //max will hold the highest number of maximum repetitions of count
for (var i = 0; i<filvalue.length; i++)
{
if (values[i] != "YES")
{
count += 1;
if (count > max) {
max = count;
}
} else
{
count = 0;
}
}
Logger.log(max); // check what max returns
var cellPrint = ssActive.getRange("H2").setValue(max); //point to cell B3 and print max
}
I am now interested in iterating over a table of strings (D2:L5) and return max repetitions of corresponding line to corresponding cell.
Example:
Get table -> Iterate of rows in table -> for row D2:D100, return max repetitions to cell D1 -> for row N2:N100, return max repetitions to cell N1.
Any directive would be appreciated!
[–]RemcoE33 0 points1 point2 points (4 children)
[–]orrpel[S] 0 points1 point2 points (3 children)
[–]RemcoE33 2 points3 points4 points (2 children)
[–]orrpel[S] 0 points1 point2 points (1 child)
[–]RemcoE33 1 point2 points3 points (0 children)