title: Google Script - Remove duplicates in last 15 rows
body: <p>I have refer this <a href="https://developers.google.com/apps-script/articles/removing_duplicates" rel="nofollow">tutorial</a> to remove duplicates in my whole google spread sheet, but it takes much time when the sheet contains large amount of data. Because of that I need to remove duplicates(keep only one record) in last 15 non empty rows.</p>
  
  <p>This is the code.</p>
  
  <pre><code>function removeDuplicates() {
    var sheet = SpreadsheetApp.openById('11SbGOCZDiTc21Jjnh7r4XW43QNtdV2L0fGdzHDxRvdA');
    var data = sheet.getDataRange().getValues();
    var newData = new Array();
    for(i in data){
      var row = data[i];
      var duplicate = false;
      for(j in newData){
        if(row.join() == newData[j].join()){
          duplicate = true;
        }
      }
      if(!duplicate){
        newData.push(row);
      }
    }
   var first = sheet.getSheetByName("Sheet1");
   first.clearContents();
   first.getRange(1, 1, newData.length, newData[0].length).setValues(newData);
  }
  </code></pre>