Skip to content

Instantly share code, notes, and snippets.

@brianxautumn
Created April 16, 2017 23:29
Show Gist options
  • Save brianxautumn/689f63422598baa4f1f2c030048ae0ee to your computer and use it in GitHub Desktop.
Save brianxautumn/689f63422598baa4f1f2c030048ae0ee to your computer and use it in GitHub Desktop.
function selectionSort(input){
var temp;
for(var j = 0; j < input.length - 1; j++){
var min = j;
for(var i = j+1; i < input.length; i++){
if(input[i] < input[min]){
min = i;
}
}
if(min !== j){
temp = input[j];
input[j] = input[min];
input[min] = temp;
}
}
}
var test = [1 , 5, 8 ,10, 45, 100, -5];
selectionSort(test);
console.log(test);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment