I'm still on combination business on a google spreadsheet, I have 2 columns, A and B, representing currency and its code and I want all the "conversion" combinations, in both ways.
I succeeded in writing the code, but, I want now to eliminate the duplicates : I mean, in the result, I will have "Convert Dollar to Euro", "Convert Euro to Dollar", "Convert Dollar to EUR", "Euro to USD", "EUR to USD" and "USD to EUR".
But, I will also have, for example, "Euro to euro".
How can I solve this in my code :
function matrix() {
var sheet = SpreadsheetApp.getActiveSheet();
var range = 'Sheet1!B4:C19';
var destID = '1kVhuTwVr80AScne9ijtlWs9YlDf5YkixIFVVbPjoX5E';
var destcell = 'Sheet1!D27';
var curr = SpreadsheetApp.getActiveSpreadsheet().getRange(range).getValues();
var currConv = [];
for (var i = 0; i < curr.length; i++)
{
for ( var j = 0; j < curr.length; j++)
{
currConv.push(['Convert ' + curr[i][0] + ' to ' + ' ' + curr[j][0]]);
currConv.push(['Convert ' + curr[i][0] + ' to ' + ' ' + curr[j][1]]);
currConv.push(['Convert ' + curr[i][1] + ' to ' + ' ' + curr[j][0]]);
currConv.push(['Convert ' + curr[i][1] + ' to ' + ' ' + curr[j][1]]);
}
}
var destRange = SpreadsheetApp.openById(destID).getRange(destcell).offset(0, 0, currConv.length);
destRange.setValues(currConv);
}
I tried to insert something like "i != j", but it gives me an error.
Thanks a lot for your help !