Slice and Splice - Please help

Slice and Splice - Please help
0

#1

Tell us what’s happening:
Hey, how to make more efficient and solve? Thanks

Your code so far


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

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

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


#2
for (let i=0; i<mediator.length; i++){
    let newArr2=arr2.splice(n,0,mediator[i]);
}

let and other variable keywords are for declaring new variables only.


#4

Alright, missed that, thank you. Code still not passing though :face_with_raised_eyebrow:


#5

arr2 has to remain the same, so you can’t use splice on arr1 or arr2.


#6

But when would splice enter the code then? It’s required


#7

You can use splice, but not on arr1 and arr2, since those variables have to remain unchanged.

You can use splice on another variable.