Tell us what’s happening:
Hello, I solved the challenge, but along the way I ran into a problem where I ended up with an empty array after I had set my combinedArrs variable = to my spliced combinedArrs array.
I’m having trouble understanding why that resulted in an empty array. It must mean I am misunderstanding something and I don’t want to continue with flawed logic in my own reasoning.
The provided code is below with comments.
Appreciate the help
**Your code so far**
function frankenSplice(arr1, arr2, n) {
let combinedArrs = arr2.slice(0);
// currently working code which passes the challenge
combinedArrs.splice(n, 0, ...arr1);
// but if I use the following line instead, it returns an empty array instead
// combinedArrs = combinedArrs.splice(n, 0, ...arr1);
return combinedArrs;
}
console.log(frankenSplice([1, 2, 3], [4, 5, 6], 1));
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.104 Safari/537.36
.
Challenge: Slice and Splice
Link to the challenge: