본문 바로가기

Algorithms

freeCodeCamp - 12. Slice and Splice [Basic Algorithm Scripting]

Slice and Splice

 

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

 

www.freecodecamp.org

 

function frankenSplice(arr1, arr2, n) {
  let a2_1 = arr2.slice(0, n)
  let a2_2 = arr2.slice(n)
  let arr3 = [...a2_1, ...arr1, ...a2_2]

  return arr3;
}

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