Eliminate combination duplicates in google spreadsheet -


i'm still on combination business on google spreadsheet, have 2 columns, , b, representing currency , code , want "conversion" combinations, in both ways.

i succeeded in writing code, but, want eliminate duplicates : mean, in result, have "convert dollar euro", "convert euro dollar", "convert dollar eur", "euro usd", "eur usd" , "usd eur".

but, have, example, "euro euro".

how can solve in 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 = [];    (var = 0; < curr.length; i++)   { ( var j = 0; j < curr.length; j++)  {    currconv.push(['convert ' + curr[i][0] + ' ' + ' ' + curr[j][0]]);   currconv.push(['convert ' + curr[i][0] + ' ' + ' ' + curr[j][1]]);   currconv.push(['convert ' + curr[i][1] + ' ' + ' ' + curr[j][0]]);   currconv.push(['convert ' + curr[i][1] + ' ' + ' ' + curr[j][1]]); }   }             var destrange = spreadsheetapp.openbyid(destid).getrange(destcell).offset(0, 0, currconv.length); destrange.setvalues(currconv); }  

i tried insert "i != j", gives me error.

thanks lot !

first need find index positions of duplicates. there stackoverflow answers finding duplicates in array, following link:

stackoverflow - answer - find duplicates

i adapted code @ above link case.

function removeduplicates(arr) { //code adapted https://stackoverflow.com/a/840849/2946873    arr = [9, 9, 9, 111, 2, 3, 3, 3, 4, 4, 5, 7];    var i,       len=arr.length,       out=[],       obj={},       hasitalreadybeenfound="",       indexpositionstodelete=[];    (i=0;i<len;i++) {     //check if value in object     hasitalreadybeenfound = obj[arr[i]];     if (hasitalreadybeenfound!==undefined) {       logger.log('index: ' + + " dup!");       indexpositionstodelete.push(i);     };      obj[arr[i]]=0;   }    //this creates array of values duplicates.  not there index number.   //for "use case", following section of code not needed, sake of demonstration i've left in.   (i in obj) {     out.push(i);   }    //return out;   logger.log('output: ' + out);   //log indexes delete   logger.log('indexpositionstodelete: ' + indexpositionstodelete);    //delete value in every cell duplicate   (i=0;i<indexpositionstodelete.length;i+=1) {     //to - range - delete cell value     //match index value of array row number, may different    }; } 

Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -