I've been tackling this challenge:
Below you'll find the code I've come up with so far:
/**
Do not return anything, modify nums1 in-place instead.
*/
function merge(nums1, m, nums2, n) {
nums2.forEach(i => {
if (i > 0) {
nums1.push(i)
}
})
nums1.sort()
for (let i = 0; i < nums1.length; i++) {
if (nums1[i] == 0) {
nums1.splice(i, 1)
}
}
};
This is the input ([1,2,3,0,0,0], 3, [2,5,6], 3)
The output I'm getting is: [0,1,2,2,3,5,6]
However, I expected it to be: [1,2,2,3,5,6]
Any insights on why this might be happening?
Thank you in advance!