Created
April 16, 2017 23:22
-
-
Save brianxautumn/cfab32e476eafef249abc4aac601f142 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 insertionSort(input){ | |
var j; | |
var temp; | |
for(var i = 1; i < input.length; i++){ | |
j = i; | |
while(j > 0 && input[j-1] > input[j]){ | |
temp = input[j]; | |
input[j] = input[j-1]; | |
input[j-1] = temp; | |
j--; | |
} | |
} | |
} | |
var test = [1 , 5, 8 ,10, 45, 100, -5]; | |
insertionSort(test); | |
console.warn(test); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment