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