enh(Javascript): Delay swapping (#653)

pull/657/head
atulll 2021-12-30 18:18:16 +05:30 committed by GitHub
parent ca62f9158c
commit e8bb90680d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 5 deletions

View File

@ -8,12 +8,11 @@ function selectionSort(array) {
if (array[j] < array[i]) { if (array[j] < array[i]) {
minIndex = j; 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 // return sorted array