Q:

how to remove duplicate lines from a tex file (or string variable) using a google app script

i have a text file in google drive, that is automatically generated, and in the process, duplicated lines are created. I now how to get the content into a string variable.
Is is possible to remove the duplicate lines? I don't mind if the order of the lines is changed or if blanc lines are erased...
Regards,

A:

After a few attempts, i got this
function revomeduplicatedlines(string){  
  var array = string.split('\n');
  Logger.log(array);
  var newarray = [];
  newarray.push(array[0]);

  for (var i = 1; i<array.length; i++){
     if (newarray.toString().indexOf(array[i])>=0){
        Logger.log('duplicate line found');
      }      
      else {
        Logger.log('not duplicate line found');
        newarray.push(array[i]);
      }
    }    
  var newstring = newarray.toString().replace(/,/g, '\n');
  return newstring;
  }

Is it improvable?
Regards,

