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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:58:45+00:00 2026-06-13T09:58:45+00:00

I am stuck on the following function which appears in a few other posts

  • 0

I am stuck on the following function which appears in a few other posts I’ve also reviewed.

function findSequence(goal) {
  function find(start, history) {
    if (start == goal)
      return history;
    else if (start > goal)
      return null;
   else
      return find(start + 5, "(" + history + " + 5)") ||
             find(start * 3, "(" + history + " * 3)");
 }
  return find(1, "1");
}

print(findSequence(24));

Also given in this link.

Javascript..totally lost in this tutorial

In the above explanation, the answer instead tried to set a goal of 11. They have a start of 1, which is first tested against 11, and then a start of 6 which is tested against 11.

I understand these first two steps. However, I do not understand the leap from the 2nd step (comparing start:6 to goal:11) to the third step (comparing start:3 to goal:11).

How does start go from 6, back down to 3, and then back up to 11 (fourth bullet)?

  • 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-13T09:58:47+00:00Added an answer on June 13, 2026 at 9:58 am

    Ok, here is a version of the code which was enhanced with console log statements. Open Chrome/Opera/Firefox eveloper tools and execute this code there:

    function findSequence (goal) {
      function find (start, history, depth) {
        depth = depth || 0;
        console.log( Array( ++depth ).join('--> '), start, goal, history );
        if (start == goal) {
          console.warn( 'history' );
          return history;
        } else if (start > goal) {
          console.error( 'null' );
          return null;
        } else {
          console.info('recursion!');
          return find(start + 5, "(" + history + " + 5)", depth) ||
                 find(start * 3, "(" + history + " * 3)", depth);
        }
      }
      return find(1, "1");
    }
    
    console.info( findSequence(24) );
    

    You will get a call trace of this program, and hopefully will grasp the concept of recursion visually, by looking on the trace.

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

Sidebar

Related Questions

I'm stuck on following matter: I have a datagrid with 10 items... I also
I'm a stuck with the following function: <script type=text/javascript> function removeElement($parentDiv, $childDiv){ if (document.getElementById($childDiv))
I'm stuck with the following code: $('div:jqmData(panel=main) div:jqmData(role=content)').live('click', function(event) { hideAllPanels(); alert (clicked); });
I have the following jQuery function: function GetGrandparentDiv(item) { return item.parents('div:eq(1)'); } Which is
The following function generates a 'stack level too deep (SystemStackError)' for n = 5,000
I am trying to use Hibernate+Spring in my application but stuck into following error:
I'm stuck with the following. I'm programming a game and I need to get
I'm stuck with the following scenario and appreciate any help/advice.. Requirement I have number
I'm new to wicket and stuck with the following problem: I have a table
I`m new to sql and have been stuck on the following issue for almost

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.