Slice and Splice 2 out of 6

What is wrong with my code? I checked it with console.log and got right answers. Last 2 checks out of 6

function frankenSplice(arr1, arr2, n) {
  // It's alive. It's alive!
  let arrn = arr1.slice();
  let arrn1 = arr2.slice();
  arrn1.splice(n,0, arrn);
  return arrn1;
}

frankenSplice(["claw", "tentacle"], ["head", "shoulders", "knees", "toes"], 2);

Hey @fukenist,

returns :

["head","shoulders",["claw","tentacle"],"knees","toes"]

While challenge wants you to return :

["head","shoulders","claw","tentacle","knees","toes"]

See if you can find out how to achieve that.

All the best.

1 Like

The FCC console flats the array, that’s why it may look like you’re returning just a one-dimension array instead of multi-dimension array.

Use the console from chrome developer tools to debug that. In chrome: press F12 and open the console tab, you can see what your function is returning as the last thing in the list.

1 Like

Thanks for helpful advice.
I did it not elegant and with line from stackoverflow but anyway.

function frankenSplice(arr1, arr2, n) {
  // It's alive. It's alive!
  let arrn = arr1.slice();
  let arrn1 = arr2.slice();
  arrn1.splice(n,0, arrn);
  let arrno = [].concat(...arrn1);
  return  arrno;
}

frankenSplice(["claw", "tentacle"], ["head", "shoulders", "knees", "toes"], 2);