Slice and Splice challenge confusion

Slice and Splice challenge confusion
0

#1

Tell us what’s happening:
I don’t get what, “The second array should remain the same after the function runs,” means, probably very obvious but for whatever reason it eludes me, can someone please explain it in different terms?

Your code so far


function frankenSplice(arr1, arr2, n) {
let x = arr1.slice(0,arr1.length)
arr2.splice(n,0,...x);
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/67.0.3396.99 Safari/537.36.

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


#2

I believe that “second array” refers to the argument arr2


#3

@benjaminjenney Make sure you surround your code with the spoiler tags. You had them inside the backticks which does not work. I fixed them for you. Also, make sure the opening and closing spoiler tags are on their separate lines.

It means do not mutate the second array passed into the function.

Currently, in the code you posted above, you are mutating the second arr, because splice changes the array in place.