title: Sorting arrays by subarray value in javascript
body: <p>I have an array of arrays in javascript with a distance (integer, whole number) value. I am trying to sort them, but I can't seem to get this to work.</p>
  
  <pre><code>nodes = [[{distance:15}],[{distance:123}],[{distance:2}]];
  
  function sortNodes(a,b) {
     if (a.distance &lt; b.distance)
       return -1;
     if (a.distance &gt; b.distance)
       return 1;
       return 0;
     }
  console.log(nodes.slice(0).sort(sortNodes));
  </code></pre>
  
  <p>Need some direction on what is happening here and why.</p>