Test wont pass despite output being correct?

Tell us what’s happening:
My code seems to output exactly what the challenge wants but for some reason it fails under “All elements from the first array should be added to the second array in their original order.” error and I don’t understand why.

  **Your code so far**

function frankenSplice(arr1, arr2, n) {
let newArr = []

for(let i = 0; i < arr2.length; i++){
  if(i == n){
    newArr.push(...arr1);
       newArr.push(arr2[i]);
  }else{
    newArr.push(arr2[i]);
  }
}

return newArr;
}

console.log(frankenSplice([1, 2, 3], [4, 5, 6], 1));
console.log(frankenSplice(["claw", "tentacle"], ["head", "shoulders", "knees", "toes"], 2));
console.log(frankenSplice([1, 2], ["a", "b"], 1));
  **Your browser information:**

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

Challenge: Slice and Splice

Link to the challenge:

I agree that the error message is a little confusing.

Try this test case:

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

Hi, the issue is actually from one of the testcases the challenge wasn’t showing.
I added console.log(arr1,arr2,n); at the beginning of the function,
then console.log(newArr) right before the return statement
and found this:

[ 1, 2, 3, 4 ] [] 0
[]

here the desired output would’ve been [1,2,3,4].
which means if you were to put into your function an empty arr2, your function will not insert the arr1.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.