Last active
August 29, 2015 14:19
-
-
Save vidul-nikolaev-petrov/637eb4d20f821f6f0eaa 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(list) { | |
for (var g = 0; g < list.length; g++) { | |
for (var i = list.length - 1; i > g; i--) { | |
if (list[i] < list[i - 1]) { | |
var tmp = list[i]; | |
list[i] = list[i - 1]; | |
list[i - 1] = tmp; | |
} | |
} | |
} | |
return list; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment