Return splice challenge issued

Tell us what’s happening:
I have a question in this challenge after read a solution :
why my output from frankenSplice(code below) is return empty array but if i return only strOut next line , it passed ?

Your code so far


function frankenSplice(arr1, arr2, n) {
let strOut = arr2.slice();
return  strOut.splice(n,0,...arr1);
}

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/81.0.4044.129 Safari/537.36.

Challenge: Slice and Splice

Link to the challenge:

I don’t understand your question.

if my code is
function frankenSplice(arr1, arr2, n) {
let strOut = arr2.slice();
return strOut.splice(n,0,…arr1);
}
(frankenSplice([1, 2, 3], [4, 5, 6], 1));

Output:

but if my code is

function frankenSplice(arr1, arr2, n) {
let strOut = arr2.slice();
strOut.splice(n,0,…arr1);
return strOut;
}
(frankenSplice([1, 2, 3], [4, 5, 6], 1));

Output: [4,1,2,3,5,6]

Could you explain me how ?

Splice modifies the array. It does not return a modified array.

1 Like

I got it , thanks :slight_smile:

1 Like