Basic Algorithm Scripting - Slice and Splice

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

my send array is still changing not matter what I do like set it to const etc.
Also if I store setText.splice(n, 0, …arr1);, into a variable, when I return that variable, it shows empty instead. Why’s that?

function frankenSplice(arr1, arr2, n) {
  var setText = arr2;
  setText.splice(n, 0, ...arr1);
  return setText
}

console.log(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/105.0.0.0 Safari/537.36

Challenge: Basic Algorithm Scripting - Slice and Splice

Link to the challenge:

Yes, you need to make a copy of the array. Assigning it to an other variable is not sufficient.

splice returns the removed elements, in this case you are removing zero elements, so it returns an empty array

1 Like