Skip to content

Instantly share code, notes, and snippets.

@AllThingsSmitty
Last active November 15, 2015 14:37
Show Gist options
  • Save AllThingsSmitty/73c8a59479df018accf9 to your computer and use it in GitHub Desktop.
Save AllThingsSmitty/73c8a59479df018accf9 to your computer and use it in GitHub Desktop.
Take two sorted lists of numbers and merge them into a single sorted list
var list1 = [2, 4, 5, 6];
var list2 = [3, 5, 8, 9];
merged_list = merge_sorted_list(list1, list2);
alert(merged_list);
function merge_sorted_list(list1, list2) {
merged_list = list1.concat(list2);
return merged_list.sort(numsort);
}
function numsort(a, b) {
return a - b;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment