How can you sort an array without mutating the original array?
<p>Let's suppose I wanted a sort function that returns a sorted copy of the inputted array. I naively tried this</p>

<pre><code>function sort(arr) {
  return arr.sort();
}
</code></pre>

<p>and I tested it with this, which shows that my <code>sort</code> method is mutating the array.</p>

<pre><code>var a = [2,3,7,5,3,7,1,3,4];
sort(a);
alert(a);  //alerts "1,2,3,3,3,4,5,7,7"
</code></pre>

<p>I also tried this approach</p>

<pre><code>function sort(arr) {
  return Array.prototype.sort(arr);
}
</code></pre>

<p>but it doesn't work at all.</p>

<p>Is there a straightforward way around this, prefereably a way that doesn't require hand-rolling my own sorting algorithm or copying every element of the array into a new one?</p>
