Skip to content

Instantly share code, notes, and snippets.

@brianxautumn
Created April 16, 2017 23:22
Show Gist options
  • Save brianxautumn/cfab32e476eafef249abc4aac601f142 to your computer and use it in GitHub Desktop.
Save brianxautumn/cfab32e476eafef249abc4aac601f142 to your computer and use it in GitHub Desktop.
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