var array = [5, -1, 10, -6]; array.sort(function (a, b) { return a >= 0 && b >= 0 ? b - a : a - b; }); alert(array);