The problem with your solution is that you’re returning the method. Every method is a function, It returns a value. Splice formats your array and return a value.
If you have
let ar = [1, 2];
and you run console.log(ar.splice(0, 1))
The method will return [1] and It’ll be shown in the console. So your function just return an empty array.
Anyway, you can fix It by adjusting like this:
function frankenSplice(arr1, arr2, n) {
let arr = […arr2];
arr.splice(n,0,…arr1);
return arr;
}
Try to understand what’s going on, because this concept is important.
I think I understand what you are saying. We will modify the array internally when we call a splice on it, but the method array.splice() actually returns a new empty array by default. So in the code above, I am returning an empty array. Am I correct? and thank you for explaining that to me.