function s(a, b){ return(Math.abs(a-12) < Math.abs(b-12))?-1:1; } alert([0, 4, 9, 14, 19, 24].sort(s))