title: Finding valid neighbors in 2D array
body: <p>So, I have a 4x4 2D array (it will always be these dimensions). Starting with a location on the array, some row and column, I want to find all of its valid neighbors. So far, I have a really clunky implementation.</p>
  
  <pre><code>//add row
      if ( !((row + 1) &gt; 3)) {
          //do stuff
      }
      //sub row
      if ( !((row - 1) &lt; 0)) {
          //do stuff
      }
      //add col
      if ( !((col + 1) &gt; 3)) {
          //do stuff
      }
      //sub col
      if ( !((col - 1) &lt; 0)) {
          //do stuff
      }
  ... and so on
  </code></pre>
  
  <p>This is brutal. I feel like I do not need to check every single neighbor when I start by knowing the location of the element. Any ideas?</p>