Slice and Splice arr[i] question

why is arr1[i] when added to the add area in splice returned as 3,2,1 instead of 1,2,3 ?

  **Your code so far**
function frankenSplice(arr1, arr2, n) {
let nArr =arr2.slice();
for (let i = 0; i<arr1.length; i++){
  nArr.splice(n,0,arr1[i]) 
  
}
return nArr

}
console.log(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/102.0.5005.63 Safari/537.36

Challenge: Slice and Splice

Link to the challenge:

Because arr1 is an array with [1,2,3] and i is counting up from 0. So splice is telling it to insert items from arr1 starting from index 0-2 at the index of n. So if you have your loop count backwards it should work.

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