Implement the Slice and Splice Algorithm - Implement the Slice and Splice Algorithm

Tell us what’s happening:

So I just found the “proper” solution to this lab, but up until I remembered the rest operator existed I was wrapping my brain into knots trying to find a roundabout solution and came up with something. I believe it fulfills the requirements of the tests, yet it fails all of them. I would like to know why this solution in particular does not pass.

Your code so far

const frankenSplice0 = (arr1, arr2, index) => {
  const newArr = arr2.concat(arr1);

  for (let i = 0; i < arr1.length; i++) {
    entry = newArr.pop();
    newArr.splice(index, 0, entry);
  }

  return newArr;
};

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:141.0) Gecko/20100101 Firefox/141.0

Challenge Information:

Implement the Slice and Splice Algorithm - Implement the Slice and Splice Algorithm
https://www.freecodecamp.org/learn/full-stack-developer/lab-slice-and-splice/implement-the-slice-and-splice-algorithm

Have you looked at what’s returned by the function? Try adding one of the test cases below your code and check console:

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

yes, that returns the following:
[ 4, 1, 2, 3, 5 ]

which is the correct output, but it is not passing the lab. i tried comparing both this function and the proper solution with various test cases in vscode, and both are giving me the same results, so I’m not sure why this particular solution doesn’t work/isn’t accepted.

Is that in VSCode or the fCC editor?

Test it in the fCC editor which runs in strict mode, and won’t necessarily behave the same as your VSCode environmnet.

1 Like

oooh i see the problem now! i forgot a keyword (i keep forgetting keywords like this i thought i wouldve learned by now lol), when i added it back in it accepts the solution just fine. i should keep closer attention to the console going forward. thank you for the help!

1 Like