Slice and Splice - Why this doesn't work?

Tell us what’s happening:
I tried to solve this by using spread syntax or rest parameter.
This does not work on FCC and Google Chrome console returning an empty array.
However, it works on MDN JS Demo of Splice Docs.

Can someone help me clear this confusion?
TYIA

Your code so far

FCC codes:

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

frankenSplice([1, 2, 3], [4, 5, 6], 1);

MDN codes:

var months = ['Jan', 'March', 'April', 'June'];
var months2 = ['Jan', 'March'];
months.splice(1, 0, ...months2);

Output: ["Jan", "Jan", "March", "March", "April", "June"]

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

Link to the MDN Splice:

  1. .splice() mutates the array, so the second array doesn’t stay the same
  2. .splice() returns an array containing removed elements
1 Like

as you have linked the documentation, I will point out that in the documentation there is a section about the return value that say:

Return value: An array containing the deleted elements. If only one element is removed, an array of one element is returned. If no elements are removed, an empty array is returned.

1 Like

Thank you all. It turns out I need to read the documentation better.