javascript map all paths
<p>im not able to figure out the following problem. At point 1 I could either go to point 2 or point 5. From point to I could go to 3 or 4. From point 5 I could go to 6 or 7. From 7 there is only one path to 9. I would like to calculate all the full paths. Im not looking for the fastest route or anything. I need all the paths there are in a manner that I could follow them easily.  </p>

<p>I have 2 questions:</p>

<ol>
<li><p>Im not sure im using the correct way to 'store' the options (a[1]=[2,5]). Is this ok or is there a better way ?</p></li>
<li><p>Im not sure how to solve this. Can anyone give me a clue ? Im hoping im looking in the right direction :-)</p></li>
</ol>

<p>The path:</p>

<pre><code>  1 -&gt;2 -&gt;3
        -&gt;4
    -&gt;5 -&gt;6
        -&gt;7 -&gt;8 -&gt;9
</code></pre>

<p>And the desired result:</p>

<pre><code> 1,2,3
 1,2,4
 1,5,6
 1,5,7,8,9
</code></pre>

<p>My attempt at solving this in javascript</p>

<pre><code>// this doesn't do what I need 
var a = [];
a[1]=[2,5];    
a[2]=[3,4];
a[5]=[6,7];
a[7]=[8];
a[8]=[9];

trytoloop(a,1);

function trytoloop(a,key){
    if(a[key]){
         for (var y in a[key]){
                document.write(key);

                trytoloop(a,a[key][y]);
         }
    } else {
        document.write(key);
    }
}
</code></pre>
