Tell us what’s happening:
When I console.log the output looks fine but I do not understand why it wouldn’t take
this code as a solution. I tried looking up solution but seems like people are using loops to solve this.
Your code so far
function frankenSplice(arr1, arr2, n) {
//copy over arr2 to an empty array
let copyOfArr2 = arr2.slice();
//copy the elements of arr1
let cutoutElement = arr1.slice();
//paste them into arr2 at the index of n
copyOfArr2.splice(n, 0, cutoutElement);
//return the resulting array
return copyOfArr2;
//the input arrays should remain the same(use slice)
}
frankenSplice(["claw", "tentacle"], ["head", "shoulders", "knees", "toes"], 2);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36.
Currently you’re pasting the whole first array into the second one, but you need to paste individual elements.
Easiest way to do it is to add ... (three dots, spread operator) before cutoutElement, but I guess it’s not yet introduced in the curriculum.