• Resolved tilou

    (@tilou)


    Hi

    Will this work and how?

    function fibonacci(num) {
      if (num <= 1) return 1;
    
      return fibonacci(num - 1) + fibonacci(num - 2);
    }

    In fact I want user to choose a number, and then it will generate a Fibonacci sequence of around 5 numbers

    • This topic was modified 6 years, 8 months ago by tilou.
    • This topic was modified 6 years, 8 months ago by tilou.
Viewing 1 replies (of 1 total)
  • Plugin Author codepeople

    (@codepeople)

    Hello @tilou,

    The solution is really simple, and there are multiple alternatives.

    – First alternative, defining the equation into the same equation. Assuming that the number field is the fieldname1, the equation associated to the calculated field would be similar to:

    
    (function(){
    function fibonacci(num) {
      if (num <= 1) return 1;
    
      return fibonacci(num - 1) + fibonacci(num - 2);
    }
    return fibonacci(fieldname1);
    })()
    

    – Second alternative, defining the function globally, and calling it from multiple equations:

    * Insert a “HTML Content” field with a piece of code similar to the following one as its content:

    
    <script>
    window['fibonacci'] = function(num) {
      if (num <= 1) return 1;
    
      return fibonacci(num - 1) + fibonacci(num - 2);
    };
    </script>
    

    * Now the equation associated to the calculated field would be simply:

    
    fibonacci(fieldname1)
    

    and that’s all.

    I’m sorry, but the support service does not cover the implementation of the users’ projects (forms or formulas). If you need help implementing features that are specific to your project, I can offer you a custom coding service:

    https://cff.dwbooster.com/customization

    Best regards.

Viewing 1 replies (of 1 total)
  • The topic ‘Fibonacci Sequence’ is closed to new replies.