Tell us what’s happening:
On this particular challenge I am trying to solve how to copy an array into another array and on running the code in the challenge it doesn’t work. what could be the issue. I’ve researched and I’m having trouble finding a more applicable solution Your code so far
function frankenSplice(arr1, arr2, n) {
let mArr = arr2.slice();
for (var i = 0; i < arr1.length; i++) {
return mArr.splice(n, 0, arr1[i]);
}
}
frankenSplice([1, 2, 3], [4, 5, 6], 1);
**Your browser information:**
User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.105 Safari/537.36.
When the splice method is called on an array, it will return an array with any deleted elements.
mArr.splice(n, 0, arr1[i]);
You have specified it to not delete any items (the second argument passed to the method), so it will always be an empty array that gets returned.
You have another issue in the fact that the return keyword placed before this will cause the function to exit after the very first iteration (where i is equal to 0).
See if you can make some adjustments to your logic and try again.