function sortNum(a,b){ return a-b; } var arr=[2,5,6,7,1,0,-1]; arr.sort(sortNum); //[-1, 0, 1, 2, 5, 6, 7]
function sortNum(a,b){ return b-a; } var arr=[2,5,6,7,1,0,-1]; arr.sort(sortNum); //[7, 6, 5, 2, 1, 0, -1]