Skip to content

Instantly share code, notes, and snippets.

@strongme
Created January 11, 2014 16:08
Show Gist options
  • Save strongme/8372772 to your computer and use it in GitHub Desktop.
Save strongme/8372772 to your computer and use it in GitHub Desktop.
Insertion sort
function insertionSort(a) {
for(var i=1;i<a.length;i+=1) {
if(a[i]<a[i-1]) {
var tmp = a[i];
for(var j=i-1;i>=0&&a[j]>tmp;j-=1) {
a[j+1] = a[j];
}
a[j+1] = tmp;
console.log(a);
}
}
return a;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment