Basic Algorithm Scripting: Slice and Splice --- code not working, seems right

https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-algorithm-scripting/slice-and-splice

Hey everybody, I’m a little confused here. My code seems to be returning everything correctly in the console log, and I have met the 2 requirements stating to return the original arrays unchanged, but for some reason I’m not meeting any of the requirements. I’ve copied an pasted the code provided in the hint, and that cleared the challenge with seemingly the same results as my code. Is there something I’m missing as to why my code isn’t passing?

function frankenSplice(arr1, arr2, n) {
  let arr3 =  arr2.slice(0,arr2.length);
  arr3.splice(n,0,(arr1.slice(0,arr1.length)));
  console.log(arr3);
  return arr3;
}

A link to the challenge will be helpful.

Ah, yes. My apologies. Just added.

No worries man.

There is a little difference between what challenge wants you to return and what your function is returning.

Let’s take the first test case as example :

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

should return :

[4, 1, 2, 3, 5]

Your code returns:

[4, [1, 2, 3], 5]

Try solving now.
All the best.

Tip: Use chrome’s console. It will give you a better idea about what your function returns.

1 Like

Ah okay, thanks. Yeah that makes sense. I couldn’t see it in the FCC log at the bottom because it doesn’t show the array brackets. I’ll use chrome from now on per your suggestion. Thanks that was very helpful!

1 Like

Glad i could help.
From now on, use the “Ask for help” button on challenge page whenever you need help with any of the challenges. It formats your code properly and also gives link to your challenge.

Happy coding!!

1 Like