Slice and Splice

Tell us what’s happening:

Your code so far


function frankenSplice(arr1, arr2, n) {
  // It's alive. It's alive!
  var a = arr1.slice(n,n+1);
  return arr2;
}

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

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.62 Safari/537.36.

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

Why are you returning arr2?
Here you can read about splice and slice methods:


With slice you can copy an array or part of it.

With splice you can get elements from one array, (but it changes the array from which you remove the items), and you can insert elements into an array.

You need to take elements from one array (or a copy of it) into the other (or a copy of it), in order and at the index n. And return the resulting array.

Remember that the instructions says that you can’t modify the input arrays.

To help you improve your skills,
you should write a comment above each line of code,
what you want it to do.

1 Like