Skip to content

Instantly share code, notes, and snippets.

@jremmen
Created May 30, 2014 05:31
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 jremmen/e22b163e7d49471da9cc to your computer and use it in GitHub Desktop.
Save jremmen/e22b163e7d49471da9cc to your computer and use it in GitHub Desktop.
js: insert sort
Sorting = {
insert_sort: function(xs) {
function insert(x, xs) {
if(xs.length === 0) return [x];
else return x <= xs[0] ? [x].concat(xs) : [xs[0]].concat(insert(x, xs.slice(1)));
}
return xs.length === 0 ? [] : insert(xs[0], this.insert_sort(xs.slice(1)));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment