Basic Algorithm Scripting - Slice and Splice

Tell us what’s happening:

Hello there, I’m currently trying to complete this challenge, and I’m so close, but it says that I shouldn’t modify arr2. I don’t see where I’m modifying it in the code? Please help, thanks

Your code so far

function frankenSplice(arr1, arr2, n) {
  const localArr = arr2
  localArr.splice(n,0,...arr1)
  return localArr
}

frankenSplice([1, 2, 3], [4, 5, 6], 1);

Your browser information:

User Agent is: Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36

Challenge Information:

Basic Algorithm Scripting - Slice and Splice

what do you think this does?

stores the 2nd array in the localArr variable

that’s true, but more specifically, what is it doing with the array? new array, same array… ?

I think it’s the same array.

so if it’s the same array, do you know see where you are changing arr2?

Uh do you mean do I know where I’m changing the array?

yea, you said it’s the same array

1 Like

I’m changing the array in the second line I think.

so that’s where you are changing arr2

Yeah, cuz I’m using the splice method on the localArr

does that solves your question?

if not, execute your function with this to see: Online JavaScript Compiler, Visual Debugger, and AI Tutor - Learn JavaScript programming by visualizing code

I executed the function, it doesn’t really make sense .

what does not make sense?

The visualizer you sent

can you add some more of what not makes sense? it shows what happens


Why does it say localArr not defined

it is not defined before the line in which it is defined is executed, continue with the execution to see what happens

2 Likes

It seems to give the right output when it’s finished

yes, but your issue wasn’t with the output, was it?