Basic Algorithm Scripting - Slice and Splice

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

Your code so far

function frankenSplice(arr1, arr2, n) {
 for(let i = 0; i<arr1.length;i++)
 {
   n = arr1[i];
   arr1[i] = arr2[i];
   arr2[i] = n;
 }
  return arr2;
}

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

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36 Edg/118.0.2088.46

Challenge: Basic Algorithm Scripting - Slice and Splice

Link to the challenge:

why is it impossible in this way, in fact, it also works, the meaning of the work is the same???

1 Like

I understand that this code is not suitable, but it also works, is it possible to make a few correct options, and not so that it is according to the developer’s code???

1 Like

Your code doesn’t pass the tests though.

Here, you can confirm that it doesn’t pass the first test with the following code:

// your function definition
function frankenSplice(arr1, arr2, n) {
  for (let i = 0; i < arr1.length; i++) {
    n = arr1[i];
    arr1[i] = arr2[i];
    arr2[i] = n;
  }
  return arr2;
}

// log the return value
const result = frankenSplice([1, 2, 3], [4, 5], 1);
console.log(result);

Here’s what it logs to the console

[ 1, 2, 3 ]

That is not equal to [4, 1, 2, 3, 5] which is what the test expects.

2 Likes

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