Rikri
January 15, 2019, 9:04pm
#1
I’m stuck on the challenge “Slice and Splice”. This code works, but for some reason, FCC isn’t registering it as correct.
function frankenSplice(arr1, arr2, n)
{
let arrTemp = arr2.slice(0);
arrTemp.splice(n, 0, arr1);
return arrTemp;
}
console.log(frankenSplice([1, 2, 3], [4, 5], 1)); //Prints "4,1,2,3,5" to the console
ilenia
January 15, 2019, 9:15pm
#2
Open the browser console and you will see why it is not working (spoiler: your array has a subarray)
bmansk8
January 16, 2019, 5:18pm
#3
any way to solve this issue. I seem to also have this problem.
function frankenSplice(arr1, arr2, n) {
var arr1Dupe = arr1.slice(0);
var arr2end = arr2.slice(n);
var sliced = arr2.slice(0,n);
arr1Dupe.unshift(sliced);
var nArr = arr1Dupe;
nArr.push(arr2end);
return nArr;
}
frankenSplice([1, 2, 3], ['a','b','c','d'], 2);
ilenia
January 16, 2019, 5:36pm
#4
You are actually getting this:
[["a", "b"], 1, 2, 3, ["b", "c"]]
You can use also this syntax, you just need a little change. Can you figure out what to do to push elemenents and not a subarray? Google can be your friend in this case.