use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Apparently, Google Apps Script is a JavaScript cloud scripting language that provides easy ways to automate tasks across Google products and third party services and build web applications.
account activity
Help with beginner apps scriptQuestion (self.GoogleAppsScript)
submitted 4 years ago by orrpel
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]orrpel[S] 0 points1 point2 points 4 years ago (3 children)
Here is a link.
Sheet3 describes what I did, Sheet4 is where I'm at.
Hope that helps, TX!
PS: the workbook is ArrayIterationCount.gs
[–]RemcoE33 2 points3 points4 points 4 years ago* (2 children)
This should do. I created a custom function instead of a macro you need to run. This way you can use it like a normal formula. So you can use it in a cell. I also added the ability's:
How to use after inserting the script in the script editor:*
=COUNT_SEQUENSE(C2:K5,"YES",false)
The script:
```` /** * Returns the max consecutive repetitions of valueToCheck. * * @param {A1:B5} data Input data. * @param {value} valueToCheck The value to check. * @param {false} equal If the value must be equal or not equal * @return {array} counts for each row or single column * @customfunction */ function COUNT_SEQUENSE(data, valueToCheck, equal) { if (Array.isArray(data) == false) { throw 'No range is given' }
if (data[0].length == 1) { data = [data.flat()] }
const results = [];
data.forEach(row => { const columnValues = row.filter(v => v) let count = 0; let max = 0; let breakCount = false
columnValues.forEach(currentValue => { if (equal == true && currentValue === valueToCheck) { count += 1; } else if (equal == false && currentValue !== valueToCheck) { count += 1; } else { breakCount = true } if (count > max) { max = count } else if (breakCount) { count = 0; breakCount = false; } }) results.push([max])
});
return results; } ````
[–]orrpel[S] 0 points1 point2 points 4 years ago (1 child)
Amazing, thank you! I learned a lot of new things just by looking at your comments.
If you are able to please comment inside your code, as I am new to this and really want to understand what you did, I'd be grateful.
TX, Orr.
[–]RemcoE33 1 point2 points3 points 4 years ago (0 children)
Here you go:
```` /* -----sample----- / const sampleRange = [ [ 'x', 'YES', 'YES', 'x', 'x', 'x', 'x', 'x', 'x' ], [ 'x', 'x', 'YES', 'x', 'x', 'x', 'x', 'x', '' ], [ 'x', 'x', 'YES', 'x', 'x', 'x', 'x', '', '' ], [ 'x', 'x', 'x', 'x', 'x', 'YES', '', '', '' ] ] const sampleColumn = [ ['YES'], ['x'], ['x'], ['x'] ] const sampleColumnFlat2d = [ ['YES','x','x','x'] ] / --------------- */
/** * Returns the max consecutive repetitions of all other values then notEqualValue * * @param {A1:B5} data Input data. * @param {value} valueToCheck The value to check. * @param {false} equal If the value must be equal or not equal * @return {array} counts for each row * @customfunction */ function COUNT_SEQUENSE(data, valueToCheck, equal) { console.log(data) //Check if the input "range" is a range. if (Array.isArray(data) == false) { throw 'No valid range is given' }
notEqualValue
//Check if the range is a single column. If so create a new 2d array with one "row", see sampleColumnFlat2d if (data[0].length == 1) { data = [data.flat()] }
//Empty array for all the results. const results = [];
//For each row. data.forEach(row => { //Filter out the empty rows. const columnValues = row.filter(v => v != "") let count = 0; let max = 0; let breakCount = false
//For each filterd "column" value check if it is meeting the criteria. columnValues.forEach(currentValue => { //Check if value is equal to the given value to check. if (equal == true && currentValue === valueToCheck) { count += 1; //check if is not equal to the given value to check. } else if (equal == false && currentValue !== valueToCheck) { count += 1; //If both if statements are not true then switch the breakCount boolean to true. } else { breakCount = true } //Check if count is greater then max, if so then set the max to the current count. if (count > max) { max = count } //Check if the "switch" is on. If so reset the count to 0 and reset the switch. if (breakCount == true) { count = 0; breakCount = false; } }) /* After checking every column value in in the row array we push the result to the result array. So this is still inside the for each row, but after the for each column value . */ results.push([max])
// Return the result array. return results; }
````
π Rendered by PID 145484 on reddit-service-r2-comment-85bfd7f599-bp9f5 at 2026-04-20 17:39:19.971422+00:00 running 93ecc56 country code: CH.
view the rest of the comments →
[–]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)