From e8bb90680d3685155fd317f528b68b57b00d393e Mon Sep 17 00:00:00 2001 From: atulll <39869656+underager@users.noreply.github.com> Date: Thu, 30 Dec 2021 18:18:16 +0530 Subject: [PATCH] enh(Javascript): Delay swapping (#653) --- algorithms/JavaScript/src/sorting/selection-sort.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/algorithms/JavaScript/src/sorting/selection-sort.js b/algorithms/JavaScript/src/sorting/selection-sort.js index b47d5894..3a26993a 100644 --- a/algorithms/JavaScript/src/sorting/selection-sort.js +++ b/algorithms/JavaScript/src/sorting/selection-sort.js @@ -8,12 +8,11 @@ function selectionSort(array) { if (array[j] < array[i]) { minIndex = j; } - - // swap with element at minimum index - const temp = array[minIndex]; - array[minIndex] = array[i]; - array[i] = temp; } + // swap with element at minimum index + const temp = array[minIndex]; + array[minIndex] = array[i]; + array[i] = temp; } // return sorted array