Cocktail Shaker Sort | Fixed 'standard' warnings and errors

This commit is contained in:
marsonya
2020-11-02 15:32:45 +05:30
parent 8d1278b455
commit d44ffef467

View File

@ -9,7 +9,7 @@
* *
*/ */
/** /**
* Doctests * Doctests
* *
* > cocktailShakerSort([5, 4, 1, 2, 3]) * > cocktailShakerSort([5, 4, 1, 2, 3])
@ -28,7 +28,6 @@ function cocktailShakerSort (items) {
for (j = items.length - 1; j > i; j--) { for (j = items.length - 1; j > i; j--) {
if (items[j] < items[j - 1]) { if (items[j] < items[j - 1]) {
[items[j], items[j - 1]] = [items[j - 1], items[j]] [items[j], items[j - 1]] = [items[j - 1], items[j]]
swapped = true
} }
} }
@ -36,7 +35,6 @@ function cocktailShakerSort (items) {
for (j = 0; j < i; j++) { for (j = 0; j < i; j++) {
if (items[j] > items[j + 1]) { if (items[j] > items[j + 1]) {
[items[j], items[j + 1]] = [items[j + 1], items[j]] [items[j], items[j + 1]] = [items[j + 1], items[j]]
swapped = true
} }
} }
} }
@ -47,7 +45,7 @@ function cocktailShakerSort (items) {
/** /**
* Implementation of Cocktail Shaker Sort * Implementation of Cocktail Shaker Sort
*/ */
var array = [5, 6, 7, 8, 1, 2, 12, 14] const array = [5, 6, 7, 8, 1, 2, 12, 14]
// Before Sort // Before Sort
console.log('\n- Before Sort | Implementation of Cocktail Shaker Sort -') console.log('\n- Before Sort | Implementation of Cocktail Shaker Sort -')
console.log(array) console.log(array)