Slice and Splice - Need help

Tell us what’s happening:

My code isn’t going through the tests, even though console.log shows the correct results.

Here’s what I did -
Since the original arrays should remain the same, I created a duplicate of arr2. Then using splice(), I inserted arr1 into the new array.

What am I doing wrong here?

Your code so far


function frankenSplice(arr1, arr2, n) {
  // It's alive. It's alive!
  let newArr = arr2.slice();
  newArr.splice(n, 0, arr1);
  return newArr;  

frankenSplice([1, 2, 3], [4, 5], 1);

console.log(frankenSplice([1, 2, 3], [4, 5], 1));

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36.

Link to the challenge:

The fCC challenge console won’t show you the real output. Do you mean the fCC console?

Do you mean the fCC console?


The problem is you are splicing in the entire arr2 instead of the elements of arr2. Your frankenSplice returns [ 4, [ 1, 2, 3 ], 5 ] instead of [4, 1, 2, 3, 5].

If you look at your browser’s console (Ctrl+Shft+J in Chrome) you would see this.

1 Like

On the challenge page, right-click and select ‘inspect’. Then choose ‘console’. There you can view the real output.

1 Like

Oh. Now it makes sense. Thank you so much! I’ll make changes to my code.