From a2514b9e7f425e3e41e99a39a4f3d16febce05eb Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 5 Mar 2022 20:51:03 +0100 Subject: [PATCH] Changed swap in ShellSort and Heap --- src/algorithms/sorting/shell-sort/ShellSort.js | 4 +--- src/data-structures/heap/Heap.js | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/algorithms/sorting/shell-sort/ShellSort.js b/src/algorithms/sorting/shell-sort/ShellSort.js index cdbba997..6113bc36 100644 --- a/src/algorithms/sorting/shell-sort/ShellSort.js +++ b/src/algorithms/sorting/shell-sort/ShellSort.js @@ -21,9 +21,7 @@ export default class ShellSort extends Sort { // Compare and swap array elements if needed. if (this.comparator.lessThan(array[gapShiftedIndex], array[currentIndex])) { - const tmp = array[currentIndex]; - array[currentIndex] = array[gapShiftedIndex]; - array[gapShiftedIndex] = tmp; + [array[currentIndex], array[gapShiftedIndex]] = [array[gapShiftedIndex], array[currentIndex]]; } gapShiftedIndex = currentIndex; diff --git a/src/data-structures/heap/Heap.js b/src/data-structures/heap/Heap.js index 45dfcfa2..b3ae7068 100644 --- a/src/data-structures/heap/Heap.js +++ b/src/data-structures/heap/Heap.js @@ -95,9 +95,7 @@ export default class Heap { * @param {number} indexTwo */ swap(indexOne, indexTwo) { - const tmp = this.heapContainer[indexTwo]; - this.heapContainer[indexTwo] = this.heapContainer[indexOne]; - this.heapContainer[indexOne] = tmp; + [this.heapContainer[indexOne], this.heapContainer[indexTwo]] = [this.heapContainer[indexTwo], this.heapContainer[indexOne]]; } /**