title: Most efficient algorithm to sort and remove duplicates for a list?
body: <p>Suppose I have a list like this: </p>
  
  <pre><code>[ 2, 7, 2, 3, 1, 1, 4, 5, 3, 6, 4 ]
  </code></pre>
  
  <p>And I want to sort and remove duplicates to yield: </p>
  
  <pre><code>[ 1, 2, 3, 4, 5, 6, 7 ]
  </code></pre>
  
  <p>I can achieve this by removing duplicates <em>and then</em> sorting: </p>
  
  <pre><code>const uniqueAndSorted = xs =&gt; [ ...new Set(xs) ].sort();
  </code></pre>
  
  <p>However, this seems inefficient, since I could probably detect duplicates as I do the sorting. </p>
  
  <p><strong>What is the optimal way to sort and remove duplicates from a list?</strong> </p>
  
  <p>(JavaScript implementations are preferred; the function should be non-destructive)</p>