Slice and Splice ....2

Tell us what’s happening:
Do I need to use splice?
I don’t understand why since I think I have put slice with the right parameters.

Your code so far


let arr3=[];
function frankenSplice(arr1, arr2, n) {
  // It's alive. It's alive!
     arr3.push(arr1);
     arr3.unshift(arr2.slice(0,n));
     arr3.push(arr2.slice(-n));
    
  return arr3;
}

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

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.1; 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/

Use console.log(JSON.stringify(...)) ti verify what you are returning

2 Likes

@InicianteGit1

You need to use slice and splice in your solution. If you click on the Get a hint link on the challenge page you will be taken to the hint page where you can get more information about the challenge as well as a solution to the challenge.

You have also this as global variable, it means that each time the function is called it is modified, and as testing your function will call it various times that global variable will mean that consecutive calls don’t get the correct results

Oh, I see, very useful tip, thanks. I will change it.

Yes i know get a hint, but i’m trying to avoid it since i used it b4