title: Copy 2D array into a middle of second bigger array
body: <p>Hello I'm struggling with copying an array into a middle of other bigger array. I don't see a reason why it shouldn't work even the indicies are correct. It's for <a href="https://adventofcode.com/2020/day/17" rel="nofollow noreferrer">https://adventofcode.com/2020/day/17</a>. They ask for 3D array but I need to solve it with 2D array first.</p>
  <p>I have an empty array like so</p>
  <pre><code>[
    [ '', '', '', '', '', '' ],
    [ '', '', '', '', '', '' ],
    [ '', '', '', '', '', '' ],
    [ '', '', '', '', '', '' ],
    [ '', '', '', '', '', '' ],
    [ '', '', '', '', '', '' ]
  ]
  </code></pre>
  <p>and small array</p>
  <pre><code>[ 
    [ 'X', '#' ], 
    [ '#', 'X' ]
  ]
  </code></pre>
  <p>and my goal is to put the small array into a middle of the big empty one like so</p>
  <pre><code>[
    [ '', '', '', '', '', '' ],
    [ '', '', '', '', '', '' ],
    [ '', '', 'X','#', '', ''],
    [ '', '', '#','X', '', ''],
    [ '', '', '', '', '', '' ],
    [ '', '', '', '', '', '' ]
  ]
  </code></pre>
  <p>but I get</p>
  <pre><code>[
    [ '', '', '#', 'X', '', '' ],
    [ '', '', '#', 'X', '', '' ],
    [ '', '', '#', 'X', '', '' ],
    [ '', '', '#', 'X', '', '' ],
    [ '', '', '#', 'X', '', '' ],
    [ '', '', '#', 'X', '', '' ]
  ]
  </code></pre>
  <p>My code is</p>
  <pre class="lang-js prettyprint-override"><code>let square = [ [ 'X', '#' ], [ '#', 'X' ] ]
  let cycles = 2;
  let startWidth = square.length;//square is the small array
  let finalWidth = startWidth + (cycles * 2);//cycles is part of the task it tells
  let twoD = new Array(finalWidth).fill(new Array(finalWidth).fill('')); how big is the bigger array/how many spaces from the edge to the small array
  
  if(finalWidth % 2 == 0){//just made for even numbers once I make this work will edit it for odd too
          for(let row = (finalWidth / 2) - 1; row &lt; (finalWidth / 2) + startWidth - 1; row++){
              for(let col = (finalWidth / 2) - 1; col &lt; (finalWidth / 2) + startWidth - 1; col++){
                  let i = col - (finalWidth / 2) + 1;
                  let j = row - (finalWidth / 2) + 1;
                  console.log(i, j, row, col)//logs correct indecies
                  twoD[row][col] = square[i][j]
              }
          }
      }
  
  </code></pre>
  <p>Any idea is appreciated. Thank you!</p>