Last active
November 15, 2015 14:37
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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