Slice and Splice please help me

Slice and Splice please help me
0

#1

Tell us what’s happening:

Your code so far


function frankenSplice(arr1, arr2, n) {
  // It's alive. It's alive!
  for(let i = 0; i < arr1.length; i++) {
arr2.splice(n+i, 0, arr1[i]);
}
  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

every thing is working but The second array should remain the same after the function runs. it’s not working


#3

The instruction says

The input arrays should remain the same after the function runs.

So you shouldn’t directly modify arr2 but rather create a new array, push arr2 into it and perform the action.

Good luck!


#4

thanks bro for helping me . i forgot about arr2 when i’m doing this challenge .


#5

function frankenSplice(arr1, arr2, n) {
// It’s alive. It’s alive!
let arr3=[…arr2];
for(let i = 0; i < arr1.length; i++) {
arr3.splice(n+i, 0, arr1[i]);
}

return arr3;
}

frankenSplice([1, 2, 3], [4, 5, 6], 1);
finally it’s working :v::v: