The goal is to splice all of arr1 into arr2 starting at index n.

CODE version timestamp: 2020/05/14 10:14pm EDT - release 1 to web -- page timestamp see below.

Commentary

Once again, the answer is in the source code. Control-U. "View source." Note that I did not output the return value anywhere--see below.

I'm going to give myself the additional assignment of specifically using "splice." According to MDN (see below), the 3rd parameter of splice should be an element of the array, not a whole array. So that's part of your problem. I assume the desired output is [4,1,2,3,5,6].

I set my breakpoint at "return a2;"--the return from frankenSplice(). A breakpoint isn't something you add to the code. It's something you set based on the code. I used that breakpoint to hover over a2 and make sure I had it right. I could use console.log() or console.info() or some such, but I'm trying to get you to learn the debugger.

I can hover over a2 or else look in the "Scope / Local" window in Chrome or Firefox's equivalent.

I made 2 mistakes while working on this. One is that I misread the 2nd argument / parameter to splice and didn't register that it was a delete count, so I had 1 instead of 0. The other is that I reversed which direction you wanted the splice to go. I think I have it right now. One point being that I make mistakes all the time, but they usually don't take long to fix. Another is that I'm about 95% sure I understand the problem / assignment, but not totally sure.

version 2 (5/15 version 1)

So if a1 = [0, 2, 4] &&  a2 = [1, 3, 5 ]{
That function would give us a new array = [0, 1, 2, 3, 4, 5] ?

Why speculate. Within the code, I run it. Survey says:


The above is from JavaScript. I will compare your results "by hand" below for ease of analysis:

[0, 1, 2, 3, 4, 5] // Pat's guess
 1, 0, 2, 4, 3, 5  // the code says

Remember that you're inserting elements of a1 into a2, starting with index 1.

References

Mozilla Developer Network is a friend! https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice

Debugging

This video by "Google Chrome Developers" shows "the debugger." Google search term was "using the Chrome javascript debugger" without quotes.

Page Timestamp / Version

v2 - second call to function, see time below (I'm ignoring the 2nd version from yesterday a few minutes apart)

Page History

  1. v2 - 5/15 1 - 8:42pm - running 2nd time with new param's, per Pat's question
  2. 5/14 10:20pm (posted a few minutes after) - debugging video link
  3. 5/14 10:14pm - first post - 2020 May 14