//升序数字排序
var ar = [37, 18.5, 22, 8, 4];
console.log( ar.sort(function (x, y) { return x - y; } ) );
// [ 4, 8, 18.5, 22, 37 ]
//降序数字排序
var ar = [37, 18.5, 22, 8, 4];
console.log( ar.sort(function (x, y) { return y - x; } ) );
// [ 37, 22, 18.5, 8, 4 ]