title: CoffeeScript sort array of objects by key
body: <p>I'm trying to pick up some CoffeeScript but stuck on sorting an array of objects by key. Here's what I tried:</p>
  
  <pre><code>sortByKey = (array, key) -&gt;
      array.sort( (a,b) -&gt; a[key] &lt; b[key] ? -1 : a[key] &gt; b[key] ? 1 : 0 )
  
  testarr = [{i: 5, b:7}, {i:9, b:15}, {i:-4, b:-99}]
  sortByKey(testarr, 'i')
  val = el['b'] for el in testarr
  alert val
  </code></pre>
  
  <p>My alert shows only -99, whereas I would have expected to see -99, 7, 15. What am I doing wrong?</p>