javascript array.sort not working with integers
<p>I'm having issues with javascript array sorting and integers. I have these functions defined:</p>

<pre><code>function sortA(a,b){ 
  return a - b;
}
function sortD(a,b){ 
  return b - a;
}
</code></pre>

<p>then in a jquery $.each, I put some content in the arrays:</p>

<pre><code>$('.'+sort_column).each(function(index, value) {

    var current_num = $.trim($(this).text())

    current_num = parseInt(current_num, 10); //convert to integer for numeric sorting.

    valuesArr.push(current_num);  

    console.log(typeof index); //just checking...this shows number in the console
});

var sort_asc = valuesArr.sort(sortA);
var sort_desc = valuesArr.sort(sortD);
console.log(sort_asc);
console.log(sort_desc);
</code></pre>

<p>but in the console, I get the arrays in the same order.</p>

<pre><code>//console
[1214500, 1214499, 1214497, 1214481, 1214432, 1214421, 1214419, 1214418, 1214369, 1214045, 1205691]
[1214500, 1214499, 1214497, 1214481, 1214432, 1214421, 1214419, 1214418, 1214369, 1214045, 1205691]
</code></pre>

<p>curiously, if I append a string to the end, the sorting works</p>

<pre><code>console.log( valuesArr.sort(sortD)  + "asdf");
console.log( valuesArr.sort(sortA)  + "asdf");

//console
[1214500,1214499,1214497,1214481,1214432,1214421,1214419,1214418,1214369,1214045,1205691asdf] 
[1205691,1214045,1214369,1214418,1214419,1214421,1214432,1214481,1214497,1214499,1214500asdf]
</code></pre>

<p>I don't know why I even tried that, but there you go. This is the first time I've worked with this method, so I've likely missed something quite basic. Many thanks for any help!</p>
