Slice and Splice challenge problem

Hey guys on the basic algorithm scripting lessons I made this code for the slice and splice part the problem is I put every test input on my code and all of them works without problem with same order. But tests are failing after I execute the code I couldn’t understand whats wrong with my code? Thanks in advance.

MyCode


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

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

Your browser information:

User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:66.0) Gecko/20100101 Firefox/66.0.

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

Hey your code works fine. But according to the immutability principle of Functional Programming (Which is covered after this section), you shouldn’t change the input parameters. The hint is the last test case.

The second array should remain the same after the function runs.

Try to solve it now.

Ohh now I get it. Thanks for the information.

1 Like