Skip to content

Instantly share code, notes, and snippets.

@valikos
Created March 14, 2016 19:45
Show Gist options
  • Save valikos/b116f587171eff33da5f to your computer and use it in GitHub Desktop.
Save valikos/b116f587171eff33da5f to your computer and use it in GitHub Desktop.
var unsortArray = [3, 5, 2, 7, 6, 8, 9, 1, 0, 4]
function selectionSort(array) {
n = array.length;
for (i = 0; i < n - 1; i++) {
var smallest = i
for (j = i + 1; j < n; j++) {
if (array[j] < array[smallest]) {
smallest = j
}
}
var tmp = array[smallest];
array[smallest] = array[i];
array[i] = tmp;
}
return array;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment