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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:25:38+00:00 2026-05-28T03:25:38+00:00

so I am fairly new to javascript and I was trying to write a

  • 0

so I am fairly new to javascript and I was trying to write a special shift scheduling code for a friend. The way it currently works is as follow :

function walk(currentDay) {
    var today = allWorkDays[currentDay]; // An array of all workdays we need to schedule
    var vertices = fetchCombinationsForToday(today); // Fetch an array of 0 length or more
                                                // containing possibilities for the day
                                                // according to rules set by user
    for (var i=0; i<vertices.length; i++) {
         [we add the vertices[i] to a running array]
         walk(currentDay+1);
    }
    if (currentDay == sumOfAllDays) { // We are at a leaf
           analyzeSchedule(); // This will keep a copy of the current schedule 
                              // if it has a higher score than X
    }
    [some business to pop the last node/day we added to our global array]
}

Now the rules specified in the comments are rules that usually analyze the last 5-10 last added elements(days) and return what could be the shifts for today.

The problem I have here is that I want the program to be able to come up with schedules even with an array of more than a thousand days, but I would exceed the function calls limit due to recursion. Is there any way to walk a tree without using recursion in javascript? I can’t seem to find one even though most say that problems solvable by recursion can be solved by loops and vice versa.

Keep in mind that the vertices array is big (20-30 elements) early in the tree but quickly gets small (0-5 elements). I never ran this code [EDIT: and got a “function calls limit reached” error] by the way it is all theory [EDIT: the fact that I will reach it] for now.

  • 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-28T03:25:39+00:00Added an answer on May 28, 2026 at 3:25 am

    JavaScript Arrays provide methods to push/pop and shift/unshift values onto/off of their beginning and end, so you can use them like a queue. For example:

    var a = [0, 1, 2];
    a.push(3); // => 3
    a; // [0, 1, 2, 3]
    a.shift(); // => 0
    a; // [1, 2, 3]
    a.pop(); // => 3
    a; // [1, 2]
    

    This way you can walk a tree structure and keep track of nodes to-be-visited by pushing and popping/unshifting from an array.

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

Sidebar

Related Questions

I'm fairly new to JavaScript and am trying to write some code that lists
I'm fairly new to Javascript/JQuery. I'm trying to write an app that takes text
I'm fairly new to JQuery and Javascript in general. I don't think I'm trying
I'm fairly new to jQuery and JavaScript, and I've been trying to implement a
I'm fairly new to javascript. I downloaded some code to make an autocompleter for
Being fairly new to JavaScript, I'm unable to discern when to use each of
I fairly new to JQuery and perhaps trying to achieve something that might be
I'm fairly new to ASP.NET and trying to learn how things are done. I
I am fairly new to Emacs and I have been trying to figure out
I'm fairly new to jQuery still and am trying to pick up ways 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.