Here is the link to my JavaScript Insertion Sort Algorithm
Quite simply, I just can't figure out why I can't get that pesky arr[0] to get sorted correctly. I've tried everything I know of. sigh
It's pretty close though.
Any idea's
var aoo = [5,2,4,6,1,3];
function jInsertionSort(a) {
for(var j=2; j<a.length; j++){
//console.log(j);
var key = a[j];
var i = j - 1;
while (i > 0 && a[i] > key) {
a[i+1] = a[i];
i = i-1;
}
a[i+1]=key;
}
return a;
}
var aooSorted = jInsertionSort(aoo);
console.log("jInsertionSort = ["+aooSorted+"]");
?