Skip to content

Instantly share code, notes, and snippets.

@NathanEpstein
Created April 1, 2015 18:05
Show Gist options
  • Save NathanEpstein/84557ede44100d996c5f to your computer and use it in GitHub Desktop.
Save NathanEpstein/84557ede44100d996c5f to your computer and use it in GitHub Desktop.
insertion sort in js
function insertSort(arr){
for (var i=1;i<arr.length;i++){
var j = i;
while ((j > 0) && (arr[j-1] > arr[j])){
var pivot = arr[j];
arr[j] = arr[j-1];
arr[j-1] = pivot;
j -= 1;
}
}
return arr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment