I didn’t know how to use splice() so I used other ways to solve the problem.
what did I do wrong here?
function frankenSplice(arr1, arr2, n) {
let result = [];
let array1 = arr1.toString();
let array2 = arr2.toString();
for (let i = 0; i<array1.length; i++){
for (let j = 0; j<array2.length; j++){
if (array1[j] == n){
return result += array2[j] + array1 + array2.slice(1);
}
}
}
return result;
}
console.log(frankenSplice([1, 2, 3], [4, 5], 1));
It should return [4, 1, 2, 3, 5], however my code returns [41,2,3,5].
I wanted to do arr1.split() so there will have a comma between 4 and 1, but it says arr1.split is not a function.
I feel like I am so close to the answer but also feel that my logic could be totally wrong.