I was under the impression that in order to sort an array of numbers you had to do the following:
var numbers = [4, 1, 2, 3];
function compare(a, b) {
return a - b;
}
numbers.sort(compare);
However, I found that the following seems to work:
var numbers = [5, 3, 2, 6, 4, 7];
var sortNumbers = numbers.sort();
console.log(sortNumbers);
Is there anything wrong with doing it this way? It seems to work in all cases for me.