Slice and splice test

Tell us what’s happening:
Describe your issue in detail here.

i dunno what is wrong with my code but , i feel this should pass the challenge but it isnt.
Your code so far


function frankenSplice(arr1, arr2, n) {
 n=0;
 let array2=arr2.slice();
 for (let i=0; i < arr1.length; i++){
   array2.splice(n,0,arr1[i]);
   n++
 }
return array2;
}

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/91.0.4472.124 Safari/537.36

Challenge: Slice and Splice

Link to the challenge:

why are you overwriting one of the function parameters?

because the way my code is set up , i wanted to set the index initially at 0

so you are always adding the items to add at index 0

what are the requirements instead? maybe check them again

there is not usually a parameter given so you can not use it

it wants to splice arr1 to a copy aray of arr2. so i set the index to 0 to so the first element go to index 0. array index 1 moves to index 1 and third element goes to index 2 . because the computer reads the first element of the array at index 0 not 1. i used the console log and it counted from 1-6 which shhould pass the test.

apparently i changed the parameter back to the initial and the test works. the odd thing is the directions wanted it to go in order. which at the index starting at one doesnt go in order since it returns 41235]. the funny thing is i check my code from the solution and they changed the paramter to 0 there to. but apparently it wont pass. if u do that. anyways thanks alot

From instructions

Begin inserting elements at index n of the second array.

You were not doing that, you were just starting at index 0 of the second array


I don’t see either of the solutions changing the value of n before starting adding the elements, where did you see it?

your right, i dont see it either. i thought i did. i guess i came up with that on my own. for a momment it made sense to do it in order for it to return from the order of 1-6 but if leaving like it is passed the challenge im fine with it.

as long as you understand why one version works and the other doesn’t

1 Like