title: Sorting in JavaScript: Shouldn't returning a boolean be enough for a comparison function?
body: <p>I have always successfully sorted my arrays like this (when I did not want the standard lexicographic ordering):</p>
  
  <pre><code>var arr = […] // some numbers or so
  arr.sort(function(a, b) {
      return a &gt; b;
  });
  </code></pre>
  
  <p>Now, someone told me this was wrong, and that I would need to <code>return a-b</code> instead. Is that true, and if yes why? I have tested my comparison function, and it works! Also, why would my solution <a href="https://stackoverflow.com/q/16096872/1048572#answers">be so common</a> when it is wrong?</p>