Slice and Splice, need help

Slice and Splice, need help
0

#1

Tell us what’s happening:
I’m trying to push the contents from arr2 into a new array. But I just can’t get the second array to stay the same.

Your code so far


function frankenSplice(arr1, arr2, n) {
  var newArr = [];
    for(let i = 0; i < arr1.length; i++) { 
        arr2.splice(n+i, 0, arr1[i]);
        newArr = arr2;
    }
  return newArr;
}



frankenSplice(["claw", "tentacle"], ["head", "shoulders", "knees", "toes"], 2);

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) 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

This problem with splice is (part of) the reason slice exists

You should read up on the differences between slice and splice - I won’t spoil it but you should be able to see exactly how to beat the challenge after that!


#3

What would slicing do?


#4

It’s worth looking up exactly what they both do:

The first description of both should help you out a lot!