Tell us what’s happening:
Hi,
could someone tell me why with my solutions (one uses the …spread and it’s in comments) I get this message? I do make copies of the arrays (I think)
// running tests
The second array should remain the same after the function runs.
// tests completed
// console output
[ 4, 1, 2, 3, 5, 6 ]
Thank you
L
Your code so far
function frankenSplice(arr1, arr2, n) {
let elements = arr1.slice(0);
let totalArray = arr2;
for (let i = 0; i < arr1.length; i++){
totalArray.splice(n+i, 0, elements[i])
};
return totalArray ;
}
console.log(frankenSplice([1, 2, 3], [4, 5, 6], 1));
/*
function frankenSplice(arr1, arr2, n) {
let totalArray = arr2;
totalArray.splice(n, 0, ...arr1)
return totalArray;
}
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/83.0.4103.61 Safari/537.36
.
Challenge: Slice and Splice
Link to the challenge: