Having trouble passing the Slice and Splice challenge

Having trouble passing the Slice and Splice challenge
0.0 0

#1

https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-algorithm-scripting/slice-and-splice

function frankenSplice(arr1, arr2, n) {
// It’s alive. It’s alive!
let ans = […arr2];let re = […arr1];
ans.splice(n,0,re);
console.log(ans);
return ans;
}
frankenSplice([1, 2], [“a”, “b”], 1);

Why i can’t pass the test!


#2

Please edit your post and provide your code in full


#3

basically you create two arrays and insert one to another
[ arr2[arr1] ]


#5

But it shows right answer in the console.


#7

i think i figured out what is wrong. It is your “dot” .
I think you are using a weird looking dot…
and weird looking double quotes

I’ve re-written the code using the correct dot and quotes
try cutting and pasting it to see if that helps

function frankenSplice(arr1, arr2, n) {

// It’s alive. It’s alive!

let ans = [...arr2];let re = [...arr1];

ans.splice(n,0,re);

console.log(ans);

return ans;

}

frankenSplice([1, 2], ["a", "b"], 1);

#8

Again it shows correct answer in console but i still can’t pass the challenge.


#9

ok, by “shows correct answer” I think you meant to say, it passes some tests, but not all?
For eg. it fails the first, second, third and fourth tests…


#10

look at the console it should pass 2nd test too.


#11

I ran your code through repl.it and this is what I got:

for this test:
frankenSplice([1, 2, 3], [4, 5], 1);
the code returns this:

Native Browser JavaScript
   
[ 4, [ 1, 2, 3 ], 5 ]
=> [ 4, [ 1, 2, 3 ], 5 ]

The correct answer should be:
[4, 1, 2, 3, 5]


#12

in order not to spoil the answer, I will send you a personal msg with the mistake I see


#13

The console in freecodecamp give you false output in vs code is this, if you read my previous answer …
0:4
1:Array(3) [1, 2, 3]
2:5


#14

Yes, you are right. My problem was that i was copying an array instead of its items by typing
[…arr1] instead of …arr1


#15

I modified your topic title to give better insight to what help you needed. In the future, please post a descriptive topic title and not just a url for the thread’s title.

Thank you