Skip to content

Instantly share code, notes, and snippets.

@galenweber
Last active April 24, 2016 20:52
Show Gist options
  • Save galenweber/9d75f47bf1ab27d86d0ff8303d5769f0 to your computer and use it in GitHub Desktop.
Save galenweber/9d75f47bf1ab27d86d0ff8303d5769f0 to your computer and use it in GitHub Desktop.
var insertionSort = function(array) {
var temp;
for (var i = 1; i < array.length; i++) {
for (var x = 0; x < i; x++ ) {
if (array[i] < array[x]) {
temp = array[i];
for (var z = i; z > x; z--) {
array[z] = array[z-1];
}
array[x] = temp;
}
}
}
return array;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment