The instructions to solve this exercise are:
"You are given two arrays and an index.
Copy each element of the first array into the second array, in order.
Begin inserting elements at index n of the second array.
Return the resulting array. The input arrays should remain the same after the function runs."
This is the code I wrote so far, I am almost there
function frankenSplice(arr1, arr2, n) {
let sumOfArrays = arr2.slice() + arr1.slice();
if (arr2 += arr1.splice(n)) {
return [sumOfArrays];
}
}
console.log(frankenSplice([1, 2, 3], [4, 5], 1));
The output is [ '4,51,2,3' ]
while the correct output should be [4, 1, 2, 3, 5]
Some indications on how to solve this exercise?
in my result a comma is missing between arr2 and arr1
and arr1 should be copied into arr2 (exactly in the middle of arr2 )