title: Sorting ascending and descending in Dart?
body: <p>I have this</p>
  
  
  
  <pre class="lang-dart prettyprint-override"><code>var nlist = [4,2,1,5];
  var compare = (a, b) =&gt; a.compareTo(b);
  nlist.sort(compare);
  print(nlist);        // [1,2,4,5]
  </code></pre>
  
  <p>and here (where I changed the <code>(b, a)</code> to <code>(a, b)</code>)</p>
  
  <pre class="lang-dart prettyprint-override"><code>var nlist = [4,2,1,5]
  var compare = (b, a) =&gt; a.compareTo(b);
  nlist.sort(compare);
  print(nlist);        // [5,4,2,1]
  </code></pre>
  
  <p>Why does this little modification change from ascending to descending order?</p>