Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8983887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:57:14+00:00 2026-06-15T20:57:14+00:00

im not able to figure out the following problem. At point 1 I could

  • 0

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.

I have 2 questions:

  1. 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 ?

  2. Im not sure how to solve this. Can anyone give me a clue ? Im hoping im looking in the right direction 🙂

The path:

  1 ->2 ->3
        ->4
    ->5 ->6
        ->7 ->8 ->9

And the desired result:

 1,2,3
 1,2,4
 1,5,6
 1,5,7,8,9

My attempt at solving this in javascript

// 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);
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T20:57:15+00:00Added an answer on June 15, 2026 at 8:57 pm

    You do not keep track of the partial path you’ve built up so far. The array idea seems fine, though. Here’s a working version with some more meaningful names: http://jsfiddle.net/YkH5b/.

    // A cleaner way of defining the next keys
    var nextKeysMap = {
        1: [2, 5],    
        2: [3, 4],
        5: [6, 7],
        7: [8],
        8: [9]
    };
    
    var fullPaths = [];
    generateFullPaths([1], 1);  // start off with partial path [1] and thus at key 1
    
    function generateFullPaths(partialPath, currentKey) {
        if(currentKey in nextKeysMap) {  // can we go further?
            var nextKeys = nextKeysMap[currentKey];  // all possible next keys
            for (var i = 0; i < nextKeys.length; i++) {  // loop over them
                var nextKey = nextKeys[i];
                // append the current key, and build the path further
                generateFullPaths(partialPath.concat(nextKey), nextKey);
             }
        } else {  // we cannot go further, so this is a full path
            fullPaths.push(partialPath);
        }
    }
    
    for(var i = 0; i < fullPaths.length; i++) {
        console.log(fullPaths[i].join(","));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am stuck with a simple problem but not able to figure out the
I am not able to figure out why it is not tracing value for
I am not able to figure out how the graphs shown here are constructed?
In SQL Server 2005, I'm trying to figure out why I'm not able to
Answer: I was able to figure out my own problem. I think the issue
I have a problem that I just haven't been able to figure out. I
This might be an obvious question. But am not able to figure it out
I was actually able to figure out my problem by assigning IDs to my
Not able to download artifacts from central maven repository. <mirrors> <!-- mirror | Specifies
We fixed an issue we had with a browser from not being able to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.