title: Google Script: Sort Array of Email Addresses to Remove Duplicates
body: <p>I pull data from a Google Event Calendar. The events include multiple point of contact e-mails (Primary, Secondary, etc.)</p>
  <p>I am currently able to collect ALL of the e-mails for the events, and this includes many duplicates.</p>
  <p>I would like to take the entire list of emails (currently delimited by &quot;;&quot;) and parse through to remove the duplicates.</p>
  <p>I created a call function that takes a string (the current list of e-mails) and should return a clean list.</p>
  <p>The code I have been trying to use:</p>
  <pre><code>function CleanEmail (InputEmailString) {
                var ReturnEmail = &quot;&quot;;
                var EmailArray = [];
                var EmailArray = InputEmailString.split(&quot;;&quot;);
                EmailArray.sort().reverse();
                var ReturnEmail = EmailArray[0];
                  for (i=1; i &lt; EmailArray.length; ++i) {
                      if (EmailArray[i-1] != EmailArray[i]) {
                      ReturnEmail += &quot;;&quot; + EmailArray[i]
                      }            // End If Statement
                    }              // End For Statement
                 return ReturnEmail;  
            }                      // Close Function
  </code></pre>
  <p>My thought is to sort the Array so that it would be in alphabetical order, then check one email back to see if there is a duplicate.</p>
  <p>Regardless of what I try the returned email list does not sort, nor does it remove any duplicates.</p>
  <p>Any help is greatly appreciated.</p>