Slice and Splice - Where did I go wrong?

I still couldn’t figure out why my code is wrong, despite getting answers as expected but failing all tests. Any help please? I have seen the guide but still I need to know where I went wrong?

Thanks in Advance,
limatgans(sgat)
My code so far


function frankenSplice(arr1=[], arr2=[], n=0) {
  // It's alive. It's alive!
  const resultArr = arr2.slice();
  resultArr.splice(n,0, arr1);
  return resultArr;
}

console.log(frankenSplice([1, 2, 3], [4, 5], 1));
console.log(frankenSplice([1, 2], ["a", "b"], 1) );
console.log(frankenSplice(["claw", "tentacle"], ["head", "shoulders", "knees", "toes"], 2));

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.3; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0.

So take a look at what you’re doing when you insert arr1 into arr2 using resultArr.splice(...) – are you inserting the values AS VALUES, or are you inserting them as an array? Taking a look at this through the console (I added a console.log(resultArr) just before your return statement), I see:

[4, [1,2,3],5]

Which shows me an array inside an array, rather than the array’s VALUES being added. What tools have you learned to quickly and easily expand that array’s values into separate ones?

1 Like