From 2ffb7b7abf693288929fa9906a8c9bba78ba2c92 Mon Sep 17 00:00:00 2001 From: vladimirschneider <42021006+vladimirschneider@users.noreply.github.com> Date: Sun, 26 Jul 2020 18:21:13 +0700 Subject: [PATCH] Swap as destructuring assignment (#497) --- src/algorithms/sorting/insertion-sort/InsertionSort.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/algorithms/sorting/insertion-sort/InsertionSort.js b/src/algorithms/sorting/insertion-sort/InsertionSort.js index 47262548..ff53c5a6 100644 --- a/src/algorithms/sorting/insertion-sort/InsertionSort.js +++ b/src/algorithms/sorting/insertion-sort/InsertionSort.js @@ -21,9 +21,7 @@ export default class InsertionSort extends Sort { this.callbacks.visitingCallback(array[currentIndex - 1]); // Swap the elements. - const tmp = array[currentIndex - 1]; - array[currentIndex - 1] = array[currentIndex]; - array[currentIndex] = tmp; + [array[currentIndex - 1], array[currentIndex]] = [array[currentIndex], array[currentIndex - 1]]; // Shift current index left. currentIndex -= 1;