Skip to content

Instantly share code, notes, and snippets.

@Monkeychip
Created December 16, 2016 21:52
Show Gist options
  • Save Monkeychip/8015dcd872aab1ffafd9a7c867f5e7cc to your computer and use it in GitHub Desktop.
Save Monkeychip/8015dcd872aab1ffafd9a7c867f5e7cc to your computer and use it in GitHub Desktop.
Compare arrays, including from other spreadsheets, and count similarities
function bamboo(){
// var ss = SpreadsheetApp.openByUrl('');
// var ss = importrange("");
var ss17 = SpreadsheetApp.getActive();
var sheet = ss17.getSheets()[1];
var values = sheet.getRange("A2:A").getValues();
var lastRow = values.filter(String).length;
//Current year
var sheet17 = ss17.getSheets()[0];
var values17 = sheet17.getRange("Z2:Z").getValues();
var lastRow17 = values17.filter(String).length;
var test = new Array();
var results = new Array();
var count = 0;
//because .getValues returns an object, need to turn into an array e.g. one column
for (var n = 0; n < lastRow17; n++){
test.push(values17[n][0]);
}; Logger.log(test.length);
for (var i = 0; i < values.length; i++) {
if(test.indexOf(values[i][0]) >=0){
results.push(test.indexOf(values[i][0]));
};
};
Logger.log(results.length);
return results.length;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment