Skip to content

Instantly share code, notes, and snippets.

@cherihung
Created April 29, 2013 22:21
Show Gist options
  • Save cherihung/5485275 to your computer and use it in GitHub Desktop.
Save cherihung/5485275 to your computer and use it in GitHub Desktop.
Google app script to use with google spreadsheets. Function calculating the occurance/count in a doc based 1 core (required) parameter and 3 optional parameters.
// CalSum Function with One Core Parameter and Three Optional Parameters
function calSumR(dR1,dP1,dR2,dP2,dR3,dP3,dR4,dP4) {
var count=dR1.length;
var t1= new RegExp(dP1);
var t2= new RegExp(dP2);
var t3= new RegExp(dP3);
var t4= new RegExp(dP4);
var s=0;
for (i=0;i<count;++i){
var v1=dR1[i][0];
var v2=dR2[i][0];
var v3=dR3[i][0];
var v4=dR4[i][0];
//match core parameter
if(t1.test(v1)){
//match one of these optional parameters
if(t2.test(v2) || t3.test(v3) || t4.test(v4)){
s=s+1;
} //end 2
} //end 1
}
return(s);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment