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 7653117
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:56:43+00:00 2026-05-31T11:56:43+00:00

I need help traversing a tree structure in a depth first fashion. I can’t

  • 0

I need help traversing a tree structure in a depth first fashion. I can’t come up with an algorithm to do it properly.

My input is this:

[
    ["A", "B", "C"],
    ["1", "2"],
    ["a", "b", "c", "d"]
]

The output should take the form:

[
    "A/1/a", "A/1/b", "A/1/c", "A/1/d",
    "A/2/a", "A/2/b", "A/2/c", "A/2/d",
    "B/1/a", "B/1/b", "B/1/c", "B/1/d",
    "B/2/a", "B/2/b", "B/2/c", "B/2/d",
    "C/1/a", "C/1/b", "C/1/c", "C/1/d",
    "C/2/a", "C/2/b", "C/2/c", "C/2/d"
]
  • 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-05-31T11:56:45+00:00Added an answer on May 31, 2026 at 11:56 am

    This should do the job:

    function traverse(arr) {
      var first = arr[0];
      var ret = [];
      if (arr.length == 1) {
        for (var i = 0; i < first.length; i++) {
          ret.push(first[i]);
        }
      } else {
        for (var i = 0; i < first.length; i++) {
          var inn = traverse(arr.slice(1));
          for (var j = 0; j < inn.length; j++) {
            ret.push(first[i] + '/' + inn[j]);
          }
        }
      }
      return ret;
    }
    
    var inp = [
      ["A", "B", "C"],
      ["1", "2"],
      ["a", "b", "c", "d"]
    ];
    
    var out = traverse(inp);
    
    console.log(out);
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Need help writing a script downloads data from google insight using c# this is
I need help on this following aspx code aspx Code: <asp:Label ID =lblName runat
I need help with this route map routes.MapRoute(Blog_Archive, Blog/Archive/{year}/{month}/{day}, new { controller = Blog,
i need help with disk_total_space function.. i have this on my code <?php $sql=select
need help... the getting input form: <select name=age> <option value=25-30>25-30</option> <option value=31-40>31-40</option> <option value=41-50>41-50</option>
Need help with an error message that I just can't figure out. I am
Need help with following situation: Users can generate their own data structures which are
need help with this please: @follows = Follow.where(admin_user_id = ?, session[:id]) This returns records
Need help with converting my VB.NET DTOs so that they can be used by
Need help in figuring out a tool which can convert a flash (.swf) chart

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.