// cocktail sort algorithm function wineSort (ARR) { the console.log ( '0th cocktail Algorithm:' + arr.join ( ',')); the let len = arr.length; for (the let I = 0; I < len / 2; I ++) { // odd the let isSort = to true; for (the let J = I; J <len -. 1 - I; J ++) { IF (ARR [J +. 1] <ARR [J]) { the let ARR = TEMP [J +. 1]; ARR [J +. 1] = ARR [J]; ARR [J] = TEMP; isSort = to false; } } the console.log ( 'algorithm cocktail' + (i + 1) + 'views:' + arr.join ( ',' )); ow (isSort) { break; } // even-numbered isSort = to true; for (the let K = len -. 1 - I; K> I; K--) { IF (ARR [K] <ARR [K -. 1]) { the let ARR TEMP = [K ]; ARR [K] = ARR [K -. 1]; ARR [K -1] = TEMP; isSort = to false; } } the console.log ( 'algorithm cocktail' + (i + 1) + ' views:' + arr.join ( ',')); IF (isSort) { BREAK; } } the console.log ( 'cocktail algorithm:' + arr.join ( ',')); } the let Array = [. 3,. 4,. 1, 2, 5, 6, 7, 8]; wineSort(array);