function eq(x, y) { if (x < y) return -1; else if (x > y) return 1; else return 0; } let num = new Array(8, 50, 2, 34, 12, 8); num.sort(eq); let text = num.join(); document.write(text);