function frankenSplice(array1, array2, index) {
let shadowCopyOfArray1 = array1.slice();
let shadowCopyOfArray2 = array2.slice();
console.log(array2.slice());// [4, 5]
console.log(shadowCopyOfArray2)//[ 4, 1, 2, 3, 5 ]
for (let i = 0; i < shadowCopyOfArray1.length; i++) {
shadowCopyOfArray2.splice(index, 0, shadowCopyOfArray1[i]);
index++;
}
return shadowCopyOfArray2;
}
console.log(frankenSplice([1, 2, 3], [4, 5], 1));
Question:
Why the result of outputing shadowCopyOfArray2 variable to console before modifying it is the result after modifying it?
It does not make any sense…
Can anybody find the problem?
perhaps it was done (tentatively) to see before and after results for troubleshooting or to be sure, if you want you can add another console log to see after results