Having trouble passing the Slice and Splice challenge

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!

Please edit your post and provide your code in full

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

But it shows right answer in the console.

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);

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

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…

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

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]

1 Like

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

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

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

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