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

  • Home
  • SEARCH
  • 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 3323874
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:21:16+00:00 2026-05-17T23:21:16+00:00

I think I have the recursion working properly, but I’m not able to get

  • 0

I think I have the recursion working properly, but I’m not able to get the originally requested item’s property set to the right value.

The goal here is to find the topmost parent (or “ancestor,” depth = 0) of the nested item (a taxonomy based on Dictionary “parent” attributes), and assign that originally requested nested item’s “ancestor” property accordingly.

For instance, in

Apples
– Red
– – Empire
– – – Fresh

“Fresh”‘s ancestor should be set to “Apples.”

While I’m attempting this on an “on-demand” and individual basis, I’m open to a solution that tags all children that are related to the same ancestor in one fell swoop or for statement, since that would probably be more efficient.

REQUEST

for (var mc:Object in taxonomy) {
        var term = taxonomy[mc];
        term["ancestor"] = getAncestor(term);
        trace("Setting " + term.name + "'s ancestor as [" + term.ancestor + "]");
        ... }

FUNCTION

function getAncestor(term:Object):String {

    var ancestor = "default";

    for(var obj:Object in taxonomy) {
        if(term.parent == taxonomy[obj].tid) { // If next object is current object's parent
            if(taxonomy[obj].depth == 0) { // And if object's parent is a root object
                // Then object's parent is the ancestor
                trace(term.name + "'s parent IS the root (" + taxonomy[obj].name + "). DONE."); // "term" here is NOT originally requested term
                return(taxonomy[obj].name); // Return DIRECTLY to function call and assign originally requested term with this name.
                break; // Get the hell out of here
            }
            else { // If object's parent is not a root object
                trace(term.name + "'s parent (" + taxonomy[obj].name + ") is NOT a root. LOOPING.");
                getAncestor(taxonomy[obj]); // Step function again with current object's parent object as current object
            }
        }
    }
    return(ancestor);
}

Finally, here is a snippet of the traced output based on my many debug statements:

treatment’s parent (Eating Disorders) is NOT a root. LOOPING.
Eating Disorders’s parent (Psychosomatic) is NOT a root. LOOPING.
Psychosomatic’s parent (Disease/Illness) is NOT a root. LOOPING.
Disease/Illness’s parent (Personal) is NOT a root. LOOPING.
Personal’s parent (Health) is NOT a root. LOOPING.
Health’s parent IS the root (People). DONE.
Setting treatment’s ancestor as [default]

As you can see, while the recursion does find the root, the originally requested item still gets the default value. What am I missing?

  • 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-17T23:21:16+00:00Added an answer on May 17, 2026 at 11:21 pm

    I’m guessing in that else statement you want:

    ancestor = getAncestor(taxonomy[obj]);
    

    Right now you’re calling the recursion but doing nothing with the return value, so you’re never updating the ancestor variable.

    Also, that break after the return statement is rather pointless. 🙂

    If I’m understanding things correctly, you might actually be able to do:

    return getAncestor(taxonomy[obj]);
    

    Otherwise your loop will keep running. Without that your loop will go over everything in the taxonomy, even if the first one it sees is the one it recurses on.

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

Sidebar

Related Questions

I think I have this working but I need advice. I'd like to know
I am working on understanding recursion, and I think I have it down alright...
I think I have a basic understanding of REST, but something I'm stuck on
I think I have a pretty simple goal but cant seem to reach it.
I have set up a Django application that uses images. I think I have
I have a question regarding ResultSet objects in Java and recursion. I was working
I'm working on a query that I think I need recursion for. In this
I think I have a synchronization problem...It may be too basic..Please help.. I have
I think I have a problem in understanding the proper way of using MVC.
I think I have a conceptual misunderstanding and would appreciate an explanation. Within a

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.