JS insertion Sort
by gentou
JavaScript
function insetionSort(arr){
for(j = 1; j < arr.length; j++){
key = arr[j];
index = j - 1;
while((index >= 0) && (arr[index] > key)){
arr[index + 1] = arr[index];
index -= 1;
}
if (index < 0){
arr[0] = key;
}
else{
arr[index + 1] = key;
}
}
return arr;
}