Slice and Splice*

Tell us what’s happening:
my code is returning the correct results, however the test keeps failing, idw why, thank you

Your code so far


function frankenSplice(arr1, arr2, n) {
  // It's alive. It's alive!
  let arr = arr2.slice(0, n);
  let arr22 = arr2.slice(n, arr2.length);
  for (let i= 0; i< arr1.length; i++) {
    arr.push(arr1[i]);
  }
  arr.push(arr22);
  console.log(arr);
  return arr;
}

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

Your browser information:

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

Link to the challenge:

I don’t see that your code is returning the correct results.

You are failing the first 4 tests - these:

frankenSplice([1, 2, 3], [4, 5], 1)should return [4, 1, 2, 3, 5].
frankenSplice([1, 2], ["a", "b"], 1)should return ["a", 1, 2, "b"].
frankenSplice(["claw", "tentacle"], ["head", "shoulders", "knees", "toes"], 2)should return ["head", "shoulders", "claw", "tentacle", "knees", "toes"].
All elements from the first array should be added to the second array in their original order.

you should be using splice instead of a for loop to insert the array

That is true too. I haven’t checked if the tests test for that.

1 Like

When I console.log the output, it corresponds to the array result of the test.

I think the issue is that the built in “fake” console that FCC provides isn’t showing you what is really happening, mainly because it doesn’t show array brackets for some strange reason. When I run this in codepen, I get:

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

which isn’t the same as what they want:

[4, 1, 2, 3, 5]

Unfortunately, in the FCC console, those both render as the same thing.

1 Like

I see, that’s an issue, cause if you can’t see the right output, yiu can’t debug, thank you foe your help.