# Algorithm Scripting

``````function frankenSplice(arr1, arr2, n) {
let combinedArr = [];

for(let i = 0; i < n; i++){
combinedArr.push(arr2[i]);
}

combinedArr.push(arr1);
combinedArr.push(arr2.slice(n));
for (let i = 0; i < combinedArr.length; i++) {
console.log("combinedArr["+i+"] is " + combinedArr[i]);
}
return combinedArr;
}
frankenSplice([1, 2, 3], [4, 5, 6], 1);
``````

here is the console output

``````"combinedArr is 4"
"combinedArr is 1,2,3"
"combinedArr is 5,6"
``````

Your final array should only be a one-dimensional array. For the first test case you are returning the following array:

``````[ 4, [ 1, 2, 3 ], [ 5 ] ]
``````

which is a two-dimensional array. You should be adding the elements of arr1 to arr2 starting at the specified index `n`. Instead when you write `combinedArr.push(arr1)`, you are pushing an array instead of the elements of an array into combinedArr. Also, remember that the slice method returns an array, so again `combinedArr.push(arr2.slice(n))` pushes an array instead of elements of an array into combinedArr.

Hello I am done with this method and it works is it correct?

``````function frankenSplice(arr1, arr2, n) {
let arr3 = arr2;
arr1.concat(arr2);
arr3.splice(n,0,...arr1);
return arr3;
}
frankenSplice([1, 2, 3], [4, 5, 6], 1);
``````

Explain to me what you think the two lines above are doing.

Also, the solution is only “correct” if you pass all the tests. Do you pass all the tests with the code above?