easy, this is the last step of the merge sort algorithm. make 2 integer variables to keep track of the index for each different input array.
Then the loop repeats as many times as there are elements adding a minimum (or maximum depending on your sort order) from the first 2 elements of the input arrays. Thus, at each iteration, the smallest possible value is added to the returned array. Just make sure your first index of input arrays is still less than the length of the first input array, if that is not the case, you know that the rest of the added items are in the second input array. Increase the index for any array from which you took the element, and then increase the index for the total array of values.
source share