Basic Algorithm Scripting: Slice and Splice

Basic Algorithm Scripting: Slice and Splice
0

#1

For this challenge, my code is passing all requirements except for: “All elements from the first array should be added to the second array in their original order.” However, when I console.log(concArr2), I seem to be getting the desired array every time. What am I doing wrong?

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

function frankenSplice(arr1, arr2, n) {
  for(let i = 0; i < arr2.length; i++){
    if(i === n){
      let arr3 = arr2.slice(0, n);
      let arr4 = arr2.slice(n, arr2.length);
      let concArr = arr3.concat(arr1);
      let concArr2 = concArr.concat(arr4);
      return concArr2;
    };
  };
};

frankenSplice([1, 2, 3], [4, 5, 6], 1);


#2

Can you format your code and post a link to the challenge?


#3

Updated it! Thank you!


#4

All elements from the first array should be added to the second array in their original order.

You are not adding them to second array, but to concArr2.


#6

Good catch! I guess the code means the same thing but doesn’t accomplish it how FCC wants. Thank you!