Hello,
I am trying to copy the array (arr1) into the array (arr2) beginning at index (n), i’m using a for loop with assignments at the desired index (n) instead of slice and splice functions, i’m working with copies of my parameters,
However, my code seems to reassign values to both the original arrays (arr2) and it’s copy (?!!) Could you please just give me a hint on what’s going wrong,
Thank you,
function frankenSplice(arr1, arr2, n) {
let arr2Copy = arr2;
let arr1Copy = arr1;
for (let i = 0; i < arr1Copy.length; i++) {
if (i == 0) { arr2Copy[n] = arr1Copy[i]; }
else { (arr2Copy.push(arr1Copy[i])); }
}
arr2Copy.push(arr2[arr2.length-1]);
return arr2Copy;
}