In Javascript, Arrays and Objects are passed by reference. So, you are saying in the first line that arr3 and arr2 are variables that point at the same Array object. When you splice into arr3, you are ALSO splicing into arr2. Run this code and check the console to see what I mean:
function frankenSplice(arr1, arr2, n) {
var arr3 = arr2;
for (var i = 0; i < arr1.length; i++) {
arr3.splice( n, 0, arr1.slice(i,i+1));
n++;
}
console.log("+++++\n","arr1\n", arr1,"\narr2\n", arr2, "\nn: ",n);
console.log("arr3");
console.log(arr3);
return arr3;
}
I can’t figure out why you have a for loop at all. Functional programming is supposed to make you not need for loops to iterate over arrays.
You should look at the console for (1), and ask why you have nested arrays in your output. The answer is on MDN’s page for splice. Visit that, and check out the left navbar to get a better idea of the inputs and outputs for splice as well. I love and live on MDN. One of my four screens ALWAYS has it up.