Merge Arrays in Order

Published by Mubashir Hassan in

Given two arrays, merge them to one array and sort the new array in the same order as the first array.

Examples

merge_sort([1, 2, 3], [5, 4, 6]) ➞ [1, 2, 3, 4, 5, 6]

merge_sort([8, 6, 4, 2], [-2, -6, 0, -4]) ➞ [8, 6, 4, 2, 0, -2, -4, -6]

merge_sort([120, 180, 200], [190, 175, 130]) ➞ [120, 130, 175, 180, 190, 200]

Notes

  • You'll always get two arrays as arguments.
  • The first array is always sorted, either asc or desc.
Watch a quick demo on how Edabit works.