Slice and splice challenge - where to start

Hey guys. I am having a hard to even know where to begin with this challenge?

Copy each element of the first array into the second array, in order.
Begin inserting elements at index n of the second array.
Return the resulting array. The input arrays should remain the same after the function runs.*/

function frankenSplice(arr1, arr2, n) {
  arr2.push(arr1.slice(" "));
  return arr2;

console.log(frankenSplice([1, 2, 3], [4, 5], 1));
// frankenSplice([1, 2, 3], [4, 5], 1) should return [4, 1, 2, 3, 5].```

I think what I have to do is somehow separate the array somehow and then join it back together based on whatever index you put it, right?

On a side note. I've been working on these algorithm scripting problems for a month and have honestly felt such an uphill confusing battle. Is there a point in time where one starts to think differently to better tackle these problems?

Hi @CodingDutchman!

Slice and Splice can get confusing, especially since they sound so so similar.

I would really recommend reading this article on the topic, as it has helped me immensely.

For this question, you want to insert the contents of arr1 into arr2 at a given index.

I don’t want to answer the question for you, but some things to think about.

  • what operator would allow you to copy the contents of an array?
  • we are given the index of arr2 where we want to insert arr1.
  • what method is used for adding elements into an array? What parameters does it take?

Learning to code and how to solve these algorithm challenges is difficult and a lot of hard work, but it does pay off, and you will start to find that you will get better at it.

I find it really helpful to not just solve the problems, but think about what each part of your code is doing. You could even comment this into your code, and then save it once you have completed the challenge.

Let me know if you have any questions.