title: Detecting closed loop in a 2D array pattern
body: <p>Let's assume that you get the following array: </p>
  
  <pre class="lang-js prettyprint-override"><code>foo = [
      [0,0,0,0,0,0,0,0,0,0],
      [0,0,0,0,0,0,0,0,0,0],
      [0,0,0,1,1,1,1,1,0,0],
      [0,0,0,1,0,0,0,1,0,0],
      [0,0,0,1,0,0,0,1,0,0],
      [0,0,0,1,1,1,0,1,0,0],
      [0,0,0,0,0,1,0,1,0,0],
      [0,0,0,0,0,1,1,1,0,0],
      [0,0,0,0,0,0,0,0,0,0],
      [0,0,0,0,0,0,0,0,0,0],
  ]
  </code></pre>
  
  <p>How can I determine if the pattern of 1s is a closed loop? I have struggled with this for a few days. I have tried a recursive loop to find neighbors and words, but when you have a more complex pattern it won't work, for example:</p>
  
  <pre class="lang-js prettyprint-override"><code>foo = [
      [0,0,0,0,0,0,0,0,0,0],
      [0,0,0,0,0,0,0,0,0,0],
      [0,0,0,1,1,1,0,0,0,0],
      [0,0,0,1,0,1,0,0,0,0],
      [0,0,0,1,0,1,0,0,0,0],
      [0,0,0,1,1,1,1,1,0,0],
      [0,0,0,0,0,1,0,0,0,0],
      [0,0,0,0,0,1,0,0,0,0],
      [0,0,0,0,0,0,0,0,0,0],
      [0,0,0,0,0,0,0,0,0,0],
  ]
  </code></pre>
  
  <p>Do someone have a magic algorithm to solve this ? :(</p>