Slice and Splice Works On VS and Fails On Website

Slice and Splice Works On VS and Fails On Website
0

#1

Tell us what’s happening:
Hi guys,i write console.log at the end for arr2 and i see the same original value on VS …why does the website refuse the answer ??

Your code so far


function frankenSplice(arr1, arr2, n) {
  let arr3=arr2.splice(n,arr2.length)
  let arr4=arr2.concat(arr1)
  arr2=arr2.concat(arr3)  
  return arr4.concat(arr3)
  
}
frankenSplice([1, 2, 3], [4, 5, 6], 1);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-algorithm-scripting/slice-and-splice


#2

Your solution mutates arr2. One of the requirements is that it remains unchanged.


#3

at the end of the function i change it back to its original form.
here is the req: "The second array should remain the same after the function runs. "
and as he requested…before the function ends…the 2nd array has its original values


#4

From a code perspective, arr2 is not the same at the end of the function as it was before. You have created a new array which contains the same values as arr2 originally had, but it is a different array. See below:

Basically, don’t mutate the array.


#5

It might contain the same values as it did before, but it is not the same array.