Tell us what’s happening:
The following code is working, and I understand why.
function frankenSplice(arr1, arr2, n) {
let localArr = […arr2];
localArr.splice(n, 0, …arr1);
return localArr;
}
But why is my other solution not working?
Instead of assinging arr2 to a variable I just chain on the splice method immediatly.
But when I do it like this, I get an empty array…
**Your code so far**
function frankenSplice(arr1, arr2, n) {
return [...arr2].splice(n, 0, ...arr1);
}
frankenSplice([1, 2, 3], [4, 5, 6], 1);
**Your browser information:**
User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36
.
Challenge: Slice and Splice
Link to the challenge: