Created
May 31, 2019 14:01
-
-
Save zinevych/c7c0dc95c3a77d660ed9386bd71f23a9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function selectionSort(array) { | |
for (var i = 0; i < array.length; i++) { | |
let min = i; // storing the index of minimum element | |
for (var j = i + 1; j < array.length; j++) { | |
if (array[min] > array[j]) { | |
min = j; // updating the index of minimum element | |
} | |
} | |
if (i !== min) { | |
let temp = array[i]; | |
array[i] = array[min]; | |
array[min] = temp; | |
} | |
} | |
return array | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment