Slice and Splice Help Needed!

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.

Link to the challenge:

Pretty close! Your output actually contains an array. Here is what I see.

[ 'head', 'shoulders', [ 'claw', 'tentacle' ], 'knees', 'toes' ]

Thank you so much for taking a look!
Oh wow, I had no idea my output was containing an array.
So I figured

copyOfArr2.splice(n, 0, arr1.slice());

instead of

let cutoutElement = arr1.slice();
copyOfArr2.splice(n, 0, cutoutElement);

should prevent that from happening
because I’m not declaring an array but instead pasting the returned elements directly.

I still couldn’t pass the test

Do I have to use loops for this challenge?

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.

Thank you so much!
Thanks to you pointing out that there was another array within an array,
I used for loop to solve the challenge!

Actually that would have solved it too! Thank you!