Anyone knows whats wrong with this recursion? It seems that it only adds the first to the second, but the second part of the second is cut off, like it was popped, without I even realizing how it came to be.
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.190 Safari/537.36.
This isn’t recursive, that means that the function may [repeatedly] call itself.
The task is:
Copy each element of the first array into the second array, in order.
Begin inserting elements at index n of the second array.
So the first line is fine, you make a copy of the second array and that’s what you’ll be adding to.
Then you say if n is 0, you just return the first array for some reason, instead of copying the elements in first array into the copy of the second array.
Then the first two arguments to splice are fine, but then you’re picking a specific item from the first array to splice in, rather than adding all of the elements in the first array
you may find the spread operator useful here. Splice takes multiple arguments, and you effectively turn an array into a list of arguments by doing ...[1,2,3] that will create 1,2,3 no array attached, but you can also spread elements into an array [...[1,2,3]] is the same as [1,2,3]