implement js cocktail sort