Hey guys,
I am assigning the splice method to result but for some reason arr2 is still being affected.
function frankenSplice(arr1, arr2, n) {
let result = arr2;
for (let i = arr1.length - 1; i >= 0; i--) {
result.splice(n, 0, arr1[i]);
}
console.log(arr2);
return result;
}
console.log(frankenSplice(["claw", "tentacle"], ["head", "shoulders", "knees", "toes"], 2));
Output:
[ ‘head’, ‘shoulders’, ‘claw’, ‘tentacle’, ‘knees’, ‘toes’ ]
[ ‘head’, ‘shoulders’, ‘claw’, ‘tentacle’, ‘knees’, ‘toes’ ]