Slice and Splice not passing test

Slice and Splice not passing test
0

#1

So i ran my code and it failed, so then i inserted console.log statements to see the result of my slicing and splicing and it returns the correct array but when i run the test it fails. Then i looked at the solution and inserted the same console.log statements to see what their output was and we have the exact same output. Please take a look, here’s my code, i left the console.log statements in it:


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

frankenSplice(["a","b"], [4, 5, 6, 7, 8, 9], 4);

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


#2

The problem is in the following line where you are inserting an array arr1 inside of splice instead of its elements.

The solution is to find a way to extract the elements of the array: arr1 and then pass them to splice.

And here’s a hint: There are many ways to do that, but the easiest of them is an ES6 feature.


#3

what if i used …arr1 instead ?


#4

Yes! the spread operator, the ES6 feature.