cocktailsort javascript implementation