javascript cocktail sort implementation