Slice and Splice,

Tell us what’s happening:

Your code so far


function frankenSplice(arr1, arr2, n) {
  // It's alive. It's alive!
  var arr = arr2.slice();
  arr.splice(n,0,arr1);

  return arr;
}

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/76.0.3809.132 Safari/537.36 OPR/63.0.3368.71.

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

Hi
please tell me what is wrong with my code

you are putting arr1 in the right position but you are putting it in as a full array so it will look like this[4, [4, 5, 6], 5, 6] you can use a spread operator to get through this

Hi
you need to use the spread operator …

function frankenSplice(arr1, arr2, n) {
  // It's alive. It's alive!
  let arr = arr2.slice();
  arr.splice(n,0,...arr1);
 return arr;
}

I see. Thanks a lot.

You don’t have to use the spread operator. It might be worth thinking about how you would do it without using spread. Just for the practice.

1 Like

Agreed, I did it without using the spread operator. And since someone gave away the answer using spread, try doing it without.

@oussama-jlassi, instead of giving away the full solution could you just post hints instead.

Hello
Spread operator are introduced in chapter 2 : ES6
and this challenge are in chapter: 6
and I have added only ... to the code of Norayr