Slice and Splice Algorithym

Tell us what’s happening:

Hey guys for some reason it ain’t passing the test and it says arr2 has been changed I would love some help

Your code so far


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

console.log(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/87.0.4280.88 Safari/537.36.

Challenge: Slice and Splice

Link to the challenge:

this will not make a copy
by now you should have found at least one method for copying an array

1 Like

I did ittt but could u explain what’s the difference in directly assigning the value and slicing it

let a = arr2 you can consider saying "this array can also be called a", it is not a copy
slice returns a copy

1 Like