Hi,
My solution for merging two sorted arrays is as below.
function mergeArrays(arr1, arr2) {
var newArray= [];
for(let i of arr1){
newArray.push(i)
}
for(let i of arr2){
newArray.push(i)
}
newArray.sort();
return newArray;
}
console.log(mergeArrays([1,3,4,5],[-2,2,6,7,8]))
this algorithm gives me the desired output:
[-2,1,2,3,4,5,6,7,8]
But then why this algorithm fails one test case?
Also, please tell me what would be the run time of this algorithm.
Thanks.