Tell us what’s happening:
Hi Guys,
I see lots of people have gone for For Loops to cycle through the array. Is this necessary, if so please could you explain why. All help much appreciated
Regards,
Danny
Your code so far
function frankenSplice(arr1, arr2, n) {
// It's alive. It's alive!
var arr3 = [...arr1] // I get slice() does not alter original though this is a precaution
var arr4 = [...arr2] // So original is not altertered
// Does this method of equating them affect the original? if not can you say arr4 = ([...arr2])
var arr3Slice = arr3.slice(0, (arr3.length - 1)); // Gut the contents of the first array
var arr4Splice = arr4.splice(n,0, arr3Slice); // At n index Frankentein the guts into it
// If splice does not like arr3Slice could you use the spread operator to put it in here?
return arr4Splice;
}
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/70.0.3538.110 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-algorithm-scripting/slice-and-splice