Created
April 1, 2015 18:05
-
-
Save NathanEpstein/84557ede44100d996c5f to your computer and use it in GitHub Desktop.
insertion sort in js
This file contains hidden or 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 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