Slice and Splice New Solution

Hi, here is a challenge in java script algorithm section.

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

Here is the solution

function frankenSplice(arr1, arr2, n) {
  // It's alive. It's alive!
  let arr = arr2.slice(0);
  arr.splice(n, 0, [...arr1]);
  return arr;
}

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

Out of 6 only two test cases passed. But when I tested it gave correct answer. Don’t know what is wrong here. Anyone help me out.

It doesn’t give the correct answer, you’re looking at something which just lists the values. What you’re doing is splicing an array in, not the values from that array — you need ...arr1, not [...arr1] - the latter is exactly the same as just writing arr1

Thanks bro. it worked.

1 Like