diff --git a/src/algorithms/sorting/shell-sort/ShellSort.js b/src/algorithms/sorting/shell-sort/ShellSort.js index 6113bc36..58859acb 100644 --- a/src/algorithms/sorting/shell-sort/ShellSort.js +++ b/src/algorithms/sorting/shell-sort/ShellSort.js @@ -12,20 +12,20 @@ export default class ShellSort extends Sort { while (gap > 0) { // Go and compare all distant element pairs. for (let i = 0; i < (array.length - gap); i += 1) { - let currentIndex = i; + let j = i; let gapShiftedIndex = i + gap; - while (currentIndex >= 0) { + while (j >= 0) { // Call visiting callback. - this.callbacks.visitingCallback(array[currentIndex]); + this.callbacks.visitingCallback(array[j]); // Compare and swap array elements if needed. - if (this.comparator.lessThan(array[gapShiftedIndex], array[currentIndex])) { - [array[currentIndex], array[gapShiftedIndex]] = [array[gapShiftedIndex], array[currentIndex]]; + if (this.comparator.lessThan(array[gapShiftedIndex], array[j])) { + [array[j], array[gapShiftedIndex]] = [array[gapShiftedIndex], array[j]]; } - gapShiftedIndex = currentIndex; - currentIndex -= gap; + gapShiftedIndex = j; + j -= gap; } } diff --git a/src/data-structures/heap/Heap.js b/src/data-structures/heap/Heap.js index b3ae7068..e12b7afc 100644 --- a/src/data-structures/heap/Heap.js +++ b/src/data-structures/heap/Heap.js @@ -95,7 +95,8 @@ export default class Heap { * @param {number} indexTwo */ swap(indexOne, indexTwo) { - [this.heapContainer[indexOne], this.heapContainer[indexTwo]] = [this.heapContainer[indexTwo], this.heapContainer[indexOne]]; + [this.heapContainer[indexOne], this.heapContainer[indexTwo]] = [ + this.heapContainer[indexTwo], this.heapContainer[indexOne]]; } /**