Created
January 19, 2016 07:49
-
-
Save ramsunvtech/ffa931ffc50371944ec9 to your computer and use it in GitHub Desktop.
Insertion sort
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 i, len = arr.length, el, j; | |
for(i = 1; i<len; i++){ | |
el = arr[i]; | |
j = i; | |
while(j>0 && arr[j-1]>toInsert){ | |
arr[j] = arr[j-1]; | |
j--; | |
} | |
arr[j] = el; | |
} | |
return arr; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment