Created
August 29, 2018 16:03
-
-
Save oliverbth05/37de86f1624e0946a19c7d3048e22167 to your computer and use it in GitHub Desktop.
Insertion Sort JS (correct)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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