title: Recursive function (maze solver) - can't find a bug;(((
body: <p>I am studying javascript and all is pretty easy to me except for some things like recursive functions. I do understand the way they work but while working with an example, I realized I can't capture the bug that prevents it from functioning...</p>
  
  <p>I have an array (map) below (0 is a closed cell, 1 means path is open) and the recursive function I am trying to use to "find" path out of this "maze" by going from its top left cell to the bottom-right one.. Basically just make the function to "find" this path of 1s. But it fails;(</p>
  
  <pre><code>var map = [
          [1,1,0,0],
          [0,1,1,0],
          [0,0,1,0],
          [0,0,1,1]
      ]
  
  function findpath(x,y) {
      if (x&lt;0 || x&gt;3 || y&lt;0 || y&gt;3) return false; //if it is outside of map
      if (x==3 &amp;&amp; y==3) return true; // if it is the goal (exit point)
      if (map[y][x]==0) return false; //it is not open
      map[y][x]=9; //here marking x,y position as part of solution path outlined by "9"
      if (findpath(x,y-1) == true) return true;
      if (findpath(x+1,y) == true) return true;
      if (findpath(x,y+1) == true) return true;
      if (findpath(x-1,y) == true) return true;
      map[y][x]=8; //unmark x,y as part of solution path outlined by "8"
      return false;
      };
  findpath(0,0);
  </code></pre>