Skip to content

Instantly share code, notes, and snippets.

@MiCkEyZzZ
Last active June 18, 2021 09:30
Show Gist options
  • Save MiCkEyZzZ/297435ae9cd7e8ecd36fc8745fa7fa17 to your computer and use it in GitHub Desktop.
Save MiCkEyZzZ/297435ae9cd7e8ecd36fc8745fa7fa17 to your computer and use it in GitHub Desktop.
Selection sort
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