Tell us what’s happening:
I’m having some trouble with this. I have a couple of ways I wanted to try it down below.
What’s next?
Your code so far
function frankenSplice(arr1, arr2, n) {
let arrLength= arr1.join(''); //gives a value to associate with length in for loop
let tempArr=[]; //array to hold results of for loop
for (var i=0; i<arrLength.length;i++){
let slice = arr1.slice(0, [i]); //loops and holds content of arr1 nomatter the size
tempArr.push(slice); //pushes held content to tempArr
}
let newArr = arr2.splice(n, 0, tempArr); //splices in tempArr contents to arr2 into newArr
return newArr;
}
frankenSplice([1, 2, 3], [4, 5, 6], 1);
The second route is as follows:
function frankenSplice(arr1, arr2, n) {
let newArr = arr2.splice(n, 0, [...arr1]);
return newArr;
}
frankenSplice([1, 2, 3], [4, 5, 6], 1);
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-algorithm-scripting/slice-and-splice/