Tell us what’s happening:
My output from my code below is:
[ 4, 5, 6 ] [ 4, 1, 2, 3, 5, 6 ]
What I expect to appear in the console is:
[ 4, 5, 6 ] [ 4, 5, 6 ]
Why is this happening? I am trying to edit arr3, not arr2, but arr2 is clearly changing. Thanks for the help in advance.
Your code so far
function frankenSplice(arr1, arr2, n) {
let arr3 = arr2;
console.log(arr2);
arr3.splice(n,0, ...arr1); //arr2 is changing here somehow
console.log(arr2);
return arr3;
}
frankenSplice([1, 2, 3], [4, 5, 6], 1);
Your browser information:
User Agent is: Mozilla/5.0 (X11; CrOS x86_64 12739.111.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.162 Safari/537.36
.
Challenge: Slice and Splice
Link to the challenge: