title: JavaScript, array.sort() two arrays based on only one of them
body: <p>I just discovered <code>array.sort()</code> and saw that I can specify how to sort like this: (example taken from <a href="http://www.w3schools.com/jsref/jsref_sort.asp" rel="nofollow">http://www.w3schools.com/jsref/jsref_sort.asp</a>)</p>
  
  <pre><code>var points = [40,100,1,5,25,10];
  points.sort(function(a,b){return a-b});
  </code></pre>
  
  <p>I've been doing my sorting manually just using Bubble Sort because the arrays are small, but I was wondering if <code>array.sort()</code> can be used in place of this:</p>
  
  <pre><code>// Sort rowCategories[i] by rowWidth[i]
  swapped = true;
  while (swapped) {
      swapped = false;
      for (var i = 0; i &lt; rowCategories.length-1; i++) {
          if (rowWidth[i] &lt; rowWidth[i+1]) {
              var swap = rowCategories[i];
              rowCategories[i] = rowCategories[i+1];
              rowCategories[i+1] = swap;
              swap = rowWidth[i];
              rowWidth[i] = rowWidth[i+1];
              rowWidth[i+1] = swap;
              swapped = true;
          }
      }
  }
  </code></pre>
  
  <p>What would I write for the built in sort to do the equivalent work?</p>