Skip to content

Instantly share code, notes, and snippets.

@richard-to
Created February 17, 2014 08:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save richard-to/9046834 to your computer and use it in GitHub Desktop.
Save richard-to/9046834 to your computer and use it in GitHub Desktop.
var insertionSort = function(list) {
var value = 0;
var pos = 0;
for (var i = 1; i < list.length; ++i) {
value = list[i];
pos = i - 1;
while (pos >= 0 && value < list[pos]) {
list[pos + 1] = list[pos];
--pos;
}
list[pos + 1] = value;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment