Slice and Splice0

Tell us what’s happening:
My code is as shown below, Please help me out. Thanks in advance.

Your code so far


function frankenSplice(arr1, arr2, n) {
  // It's alive. It's alive!
  var clone = arr2.slice(0);
  for (let i = 0; i < arr1.length; i++) {
    clone = clone.splice(n, 0, arr1[i]);
  }
  return clone;
}

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

Your browser information:

User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:67.0) Gecko/20100101 Firefox/67.0.

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

Splice returns the removed elements, so your clone is actually becoming an empty array as splice doesn’t remove anything

You can use the spread operator with splice which will save you the loop
Splice (see third optional argument) -> https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice
Spread syntax -> https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax

<redacted>

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.

If you want to compare your solution to others, use the Get a hint button on the challenge and there are alternative solutions you can compare yours to. Also, you can probably search older posts using the forum search feature or google the challenge name and find more there.

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.

Thank you for understanding.