Challenge: Merge Two Sorted Arrays

Given two sorted arrays, merge them into one array that is sorted. Implement the solution in JavaScript to see if your code runs successfully!

Problem Statement #

Implement a function that merges two sorted arrays into another sorted array. Name it mergeArrays(arr1, arr2).

Input: #

Two sorted arrays.

Output: #

A merged sorted array consisting of all elements of both input arrays.

Sample Input #

arr1 = [1,3,4,5]  
arr2 = [2,6,7,8]

Sample Output #

arr = [1,2,3,4,5,6,7,8]

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.