Created
April 16, 2017 23:29
-
-
Save brianxautumn/689f63422598baa4f1f2c030048ae0ee to your computer and use it in GitHub Desktop.
This file contains hidden or 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(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