Skip to content

Instantly share code, notes, and snippets.

@cdmz
Created January 28, 2016 22:55
Show Gist options
  • Save cdmz/8e6e6673b9f18f847ae5 to your computer and use it in GitHub Desktop.
Save cdmz/8e6e6673b9f18f847ae5 to your computer and use it in GitHub Desktop.
insertion_sort javascript
function insertion_sort(values) {
var length = values.length;
for(var i = 1; i < length; ++i) {
var temp = values[i];
var j = i - 1;
for(; j >= 0 && values[j] > temp; --j) {
values[j+1] = values[j];
}
values[j+1] = temp;
}
return values;
};
console.log(insertion_sort([7, 4, 5, 2, 9, 1]));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment