title: How does Javascript's sort() work?
body: <p>How does the following code sort this array to be in numerical order?     </p>
  
  <pre><code>var array=[25, 8, 7, 41]
  
  array.sort(function(a,b){
    return a - b
  })
  </code></pre>
  
  <p>I know that if the result of the computation is... </p>
  
  <p><strong>Less than 0</strong>: "a" is sorted to be a lower index than "b".<br />
  <strong>Zero:</strong> "a" and "b" are considered equal, and no sorting is performed.<br />
  <strong>Greater than 0:</strong> "b" is sorted to be a lower index than "a".<br /></p>
  
  <p>Is the array sort callback function called many times during the course of the sort?</p>
  
  <p>If so, I'd like to know which two numbers are passed into the function each time. I assumed it first took "25"(a) and "8"(b), followed by "7"(a) and "41"(b), so:</p>
  
  <p>25(a) - 8(b) = 17 (greater than zero, so sort "b" to be a lower index than "a"): 8, 25</p>
  
  <p>7(a) - 41(b) = -34 (less than zero, so sort "a" to be a lower index than "b": 7, 41</p>
  
  <p>How are the two sets of numbers then sorted in relation to one another?</p>
  
  <p>Please help a struggling newbie!</p>