Last active
June 18, 2021 09:30
-
-
Save MiCkEyZzZ/297435ae9cd7e8ecd36fc8745fa7fa17 to your computer and use it in GitHub Desktop.
Selection sort
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 (let i = 0; i < array.length; i++) { | |
let minIndex = i | |
for (let j = i + 1; j < array.length; j++) { | |
if(array[j] < array[minIndex]) { | |
minIndex = j | |
} | |
} | |
let tmp = array[i] | |
array[i] = array[minIndex] | |
array[minIndex] = tmp | |
} | |
return array | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment