title: JavaScript sort with numbers
body: <p>The following program (taken from a tutorial) prints the numbers in an array in order from lowest to highest. In this case, the result will be  <code>2,4,5,13,31</code></p>
  
  <p>My question relates to the paramaters "a" and "b" for the function compareNumbers. When the function is called in <code>numArray.sort(compareNumbers)</code> what numbers will be the parameters a and b for the function. Does it just move along the array. For example, start with <code>a=13</code> and <code>b=2</code>? After that, does the function run again comparing a=2 and b=31?  or would it next compare <code>a=31</code> and <code>b=4</code>?</p>
  
  <p>Can someone please explain how that part works and also how it manages to sort them from lowest to highest? I don`t see how the function manages to do the necessary calculations on the numbers in the array.</p>
  
  <pre><code>function compareNumbers(a,b) {
    return a - b;
  }
  
  var numArray = [13,2,31,4,5];
  alert(numArray.sort(compareNumbers));
  </code></pre>