What I doing wrong?

The output is correct, but the following requirement is not met and it is not letting me complete the challenge:

“All elements from the first array should be added to the second array in their original order.”

  **Your code so far**

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

for (let i=0; i < arr2.length; i++){
  newArray.push(arr2[i])
  
  if(i==n-1){
    for (let x=0; x < arr1.length; x++) {
      newArray.push(arr1[x]) 
      
    }

  }
}
arr2 = newArray
return arr2;
}

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/90.0.4430.85 Safari/537.36.

Challenge: Slice and Splice

Link to the challenge:

what happens if arr2 is empty?

you actually need to use slice and splice here, not a loop

Why? Why not return newArray?

Criteria:

The first array should remain the same after the function runs.

The second array should remain the same after the function runs.

What happens to arr2 in the closing lines of your code?

And yes, I also did this without splice and slice, but having subsequently looked at the suggested answers after completing it, its worth spending a few mins looking back at them for future use

I was referring to the original code submitted

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