title: Function to remove duplicates from Google Form
body: <p>I was  trying to make a script for a google spreadsheet that would remove duplicate entries that were submitted via a google form.  Essentially the google form writes the entries to the google spreadsheet and I wanted any google form entry that were a duplicate to an entry already submitted through the form, to be removed automatically.  This is the code that I have now:</p>
  
  <pre><code>function onFormSubmit(e) {  
   var sheet = SpreadsheetApp.openById("13ggBeSGGxhI291uPcIr0RudwxxKUigtNEN750Q2hCBM");
   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);
      }
    }
    sheet.clearContents();
    sheet.getRange(1, 1, newData.length, newData[0].length).setValues(newData);
  }
  </code></pre>
  
  <p>I know parts of it are still incorrect so i was hoping someone could help me get a better idea of what I'm doing wrong so that I can make the necessary corrections.  Thanks! </p>