Skip to content

Instantly share code, notes, and snippets.

@oliverbth05
Created August 29, 2018 16:03
Show Gist options
  • Save oliverbth05/37de86f1624e0946a19c7d3048e22167 to your computer and use it in GitHub Desktop.
Save oliverbth05/37de86f1624e0946a19c7d3048e22167 to your computer and use it in GitHub Desktop.
Insertion Sort JS (correct)
function insertionSort(arr){
var currentVal;
for(var i = 1; i < arr.length; i++){
currentVal = arr[i];
for(var j = i - 1; j >= 0 && arr[j] > currentVal; j--) {
arr[j+1] = arr[j]
}
arr[j+1] = currentVal;
}
return arr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment