var merge = function(nums1, m, nums2, n) {
//contcating two array
let array = nums2.concat(nums1)
// sort the array
array.sort((a,b) => a-b)
// remove element > m+n length
return array.slice(m+n-n)
};
This ^ function is returning -> [1,2,3,0,0,0] if i'm applying console then answer is same as expected -> [1,2,2,3,5,6]
Why is this happening ?
num1,m,num2andn?mandnare both 3? The last line you are removing index 3+3-3 ...soslice(3)will return an array without the first 3 numbers...why? and why not justmifn-n?m + n - n= m !? do you meanarray.slice(m+n,n)[1,2,3.0,0,0]and[2,5,6]. result is[1,2,2,3,5,6], must bearray.slice(3)orarray.slice(3, array.length)