Basic Algorithm Scripting - Slice and Splice

Tell us what’s happening:
Describe your issue in detail here.

Your code so far
I couldn’t get the last test case right, please can someone help me to figure out what is wrong?
Test Case : “The second array should remain the same after the function runs”

function frankenSplice(arr1, arr2, n) {
  for (let i = (arr1.length - 1); i >= 0; i--) {
    arr2.splice(n, 0, arr1[i]);

  return arr2;

console.log(frankenSplice([1, 2, 3], [4, 5], 1));

Your browser information:

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

Challenge: Basic Algorithm Scripting - Slice and Splice

Link to the challenge:

This means that you can’t make changes directly to arr2, such as:

arr2.splice(n, 0, arr1[i]);

The splice method changes the array it acts upon, so it is changing arr2.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.