Slice and Splice/ copy paste

Tell us what’s happening:
I tested it, and it returns the correct result, can someone explain why the test won’t show correct?

Your code so far

function frankenSplice(arr1, arr2, n) {
  let copied = arr1.slice(0, arr1[-1]);
  arr2.splice(n, 0, copied);
  return arr2;

console.log(frankenSplice([1, 2, 3], [4, 5], 1));

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36.

Link to the challenge:

arr1[-1] is undefined, you are writing arr1.slice(0, undefined)

Just so you know, even if it is working

this is changing arr2 even if you are asked not to

But you are also not giving the correct result, I suggest you use console.log(JSON.stringify(...)) to see what you actually returning

1 Like