freeCodeCamp Challenge Guide: Slice and Splice

Since we can’t add our own solutions directly under the threads anymore and instead have to create a topic in this section to have it added, this was my personal solution to the challenge:

function frankenSplice(arr1, arr2, n) {
  let newArr2 = [...arr2];
  for (let i = 0; i < arr1.length; i++) {
    newArr2.splice(n + i, 0, arr1[i]);
  return newArr2;

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

Essentially just splicing each arr1 element at index N + loop iteration # to correctly position each new element to avoid backwards order. Passed all checks.

This solution is pretty similar to Solution #1, so we probably will not add it.

1 Like

Out of curiosity do either n++ or n + i have any advantages over the other other than saving a line?

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.