Norayr
September 16, 2019, 4:47pm
1
Tell us what’s happening:
Your code so far
function frankenSplice(arr1, arr2, n) {
// It's alive. It's alive!
var arr = arr2.slice();
arr.splice(n,0,arr1);
return arr;
}
frankenSplice([1, 2, 3], [4, 5, 6], 1);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36 OPR/63.0.3368.71
.
Hi
please tell me what is wrong with my code
you are putting arr1 in the right position but you are putting it in as a full array so it will look like this[4, [4, 5, 6], 5, 6]
you can use a spread operator to get through this
OJL
September 16, 2019, 5:03pm
3
Hi
you need to use the spread operator …
function frankenSplice(arr1, arr2, n) {
// It's alive. It's alive!
let arr = arr2.slice();
arr.splice(n,0,...arr1);
return arr;
}
lasjorg
September 16, 2019, 5:25pm
5
You don’t have to use the spread operator. It might be worth thinking about how you would do it without using spread. Just for the practice.
1 Like
Roma
September 16, 2019, 8:57pm
6
Agreed, I did it without using the spread operator. And since someone gave away the answer using spread, try doing it without.
@OJL , instead of giving away the full solution could you just post hints instead.
OJL
September 16, 2019, 9:16pm
7
Hello
Spread operator are introduced in chapter 2 : ES6
and this challenge are in chapter: 6
and I have added only ...
to the code of Norayr