Optimized bubble sort in JavaScript. Cocktail sort | Hacker News Reader