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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:30:12+00:00 2026-06-17T21:30:12+00:00

I am working with trees in D3 and so far it has been a

  • 0

I am working with trees in D3 and so far it has been a lot of fun.
Given a user clicks on an inner node (circle), I would like to

  • provide a list of all leaf names
  • color all paths from that node leading to the leaves.

Here is some code I have written for that purpose

   var circles = nodeEnter.append("svg:circle")
      .attr("r", function(d){ return d.children ? 5 : 0; })
      .on("click", get_all_children);


    function get_all_children(d){
         var all_children = get_all_childs(d);
             console.log("end, our array has: "+all_children.length+" elements");
            all_children.forEach(function(elem){
                console.log(elem.name);
        });
}

function get_all_childs(d, all_childs){
    var all_children = new Array;
    all_children.push(all_childs);

    if(d.children){
            var children = d.children;
            for (var i = 0; i < children.length; i++) {
                var temp_array = get_all_childs(children[i], all_children);
                console.log("got from recursion: : "+temp_array.length+" children");
                all_children.push(temp_array);
            }
    }
    else{
        //return all_children;
        //console.log("end, our array has: "+all_children.length+" elements");
    }
    return all_children;
}

Looks like my recursions are not working correctly.
Can you help me with that?

  • 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-17T21:30:13+00:00Added an answer on June 17, 2026 at 9:30 pm

    Try moving var all_children = new Array; outside the scope of the get_all_childs() function. With that variable being redeclared as a new Array on each call of that function, you’ll only ever end up with the results from the final call of that function.

    Whereas, if that variable exists outside the scope of that function, as the code recurses, the values pushed onto that array will persist through multiple calls to the function.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have edits to my working tree which I would like to continue working
As a project I have been working on has grown, so has the frequency
I am working on a homework assignment that deals with binary search trees and
I'm working on building a tree structure in MySQL and have been experimenting with
I'm still working on my binary trees, and the insertion, lookup, maximum, minimum functions
I am working on an existing project that has two areas that can be
I've been working on an assignment and now I'm stuck with buggy destructors. I
I have been trying to port project im working on to PropelORM . So
This is a learning exercise in expression trees. I have this working code: class
I'm working on a DotNetNuke module that includes a tree-style navigation menu. So far,

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.