Is it because of the challenge only?

Tell us what’s happening:

hello may someone explain why code below does not work i checked the hints and i know that it should be like this as the right answer for the challenge.

the Right Answer

let results = arr2.slice();
results.splice(n, 0, ...arr1);
return results;

just for the sake of understanding, your explanation is appreciated.

Your code so far(the code that is not working!)

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

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

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36.

Challenge: Slice and Splice

Link to the challenge:

splice returns the removed elements, in this case it is removing 0 elements, so it returns an empty array
plus, splice change the array on which is called, so you are changing arr2 against challenge instructions

1 Like

Your code has been blurred out to avoid spoiling a full working solution for other campers who may not yet want to see a complete solution. In the future, if you post a full passing solution to a challenge and have questions about it, please surround it with [spoiler] and [/spoiler] tags on the line above and below your solution code.

Thank you.

1 Like