Original: Custom/Modified 'Fibonacci' Number sequenceRevised: Personalized/Altered

I am looking to create a unique variation of the Fibonacci sequence. The implementation I have in mind is as follows:

(FSM) - FSM(0) = 0,
FSM(1) = 1, 
FSM(n) = FSM(n - 2) + FSM(n - 1) / n

How can this be achieved using JavaScript? Specifically, I need to input a large integer 60000000 and generate the next 10 numbers in the sequence.

It is important to note that there is a division by 'n' in the equation involving (n-1).

Below is my current code snippet:

var fibonacci = (function() {
        var memo = {};

          function f(n) {
            var value;

            if (n in memo) {
              value = memo[n];
            } else {
              if (n === 0 || n === 1)
                value = n;
              else             
              value = f(n - 1)/n + f(n - 2);
              memo[n] = value;
            }
            console.log(value);
            return value;
          }

          return f;
        })();
fibonacci(10);

My task now requires me to "Calculate the 10 modified Fibonacci Numbers following the 60000000th element."

However, attempting to call fibonacci(60000000); will result in a crash.

Answer №1

LATEST UPDATE:

Here is a suggested solution. Input Parameters: n for the starting number, m for the total numbers to be saved.

function generateFibonacciSequence(n,m) {
    var num1 = 0, num2 = 1, sum = null, sequence = [], count = 0;

    for ( var i = 0; i <= n; i++ ) {
        if ( num1 >= n ) {
            if ( count >= m ) {
                return sequence;
            }
            sequence.push(num1);
            count++;
        }
        sum = num1 + num2;
        num1 = num2;
        num2 = sum;
    }
}

generateFibonacciSequence(60000000,10); // [63245986, 102334155, 165580141, 267914296, 433494437, 701408733, 1134903170, 1836311903, 2971215073, 4807526976]

See Demo Here

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Retrieving information from a nested .then callback

Summing it up briefly, I've been diving into the depths of learning JavaScript for a while now. After hours and hours of relentless Googling, I find myself stuck with an issue that eludes resolution, pointing to my flawed approach. The objective at h ...

The most effective method for calculating overhead is through the utilization of synchronous techniques

I'm currently developing a nodeJS app that heavily relies on synchronous methods, particularly for file operations and spawning child processes. I am looking to assess the impact of these blocking main thread activities in terms of overhead. What woul ...

Avoiding unnecessary Ajax requests using pushstate for pagination

I encountered an issue with ajax pagination using the HTML API Pushstate. Here is the code I am working with: <ul class="small"> <li> <p>a</p> </li> </ul> <ul class="paging"> <li><a ...

Issue with the Edit feature causing conflicts with the local storage and generating error messages

There seems to be an issue with my edit function that is causing it to override the local storage when I attempt to save and interfering with my delete function as well. I have searched through similar posts for a solution but have not been able to pinpo ...

Discovering, storing, and displaying JSON data in JavaScript

I am currently working on a PHP file called rows2.php that displays results from a database by showing the new id of the field in this format: {'new_id':'92'} My goal is to use JavaScript to load this data and add the new_id surrounded ...

Issue with Nextjs: getServerSideProps causing a blank page to display instead of redirecting to 404errorCode

I am facing an issue on my dynamic page where the external server returns a 404 error if the requested product is not found. However, when using getServerSideProps, instead of redirecting to a 404 page, it shows a blank page. Below is the code snippet: // ...

Retrieve the nth element from an array using a function that requires 2 arguments

During my coding journey, I encountered a challenge that has proven to be quite tricky. The task in question goes as follows: Create a function that accepts an array (a) and a value (n) as parameters Identify and store every nth element from the array in ...

Contrast: Colon vs. Not Equal Sign (Typescript)

Introduction Hello everyone, I am new to Typescript and currently grappling with some fundamental concepts. When defining a parameter for a function, I typically specify the type like this: function example(test: string){...} However, as I delve deeper ...

How to Make Client-Side Jquery Code Function in Karma Tests

I'm facing a challenging issue for which I can't seem to find a solution. In my React component, I am using jQuery to modify the classes of certain DOM nodes based on a click event. Here is a simplified version of the code: hide() { if ($(&ap ...

Node.js Express JS is currently in the process of retrieving a file

I'm currently grappling with an issue while attempting to download a file using express js. Here is the function in question: var download = function(uri, filename, callback) { request .get(uri) .on('response', function (response) { ...

Extract the entire div including all its elements and then transmit it using the PHP mail function

Currently, I am developing a feature that allows users to send an email. The email should include only one div from the page which contains elements added using the jQuery drag and clone function. I am unsure how to copy the entire div along with its child ...

Tips for displaying a specific element from an array in Objective-C

Looking to extract and assign array elements by index in Objective-C. Here's the current code snippet: NSString *String=[NSString StringWithContentsOFFile:@"/User/Home/myFile.doc"]; NSString *separator = @"\n"; NSArray *array = [String componetn ...

Is there a way to prevent downloaded files from becoming corrupted?

When the handleDownload() function is attached to a button as an event handler (onclick), allowing users to download a file, sometimes the downloaded file ends up corrupted. Is there a way to prevent file corruption? function handleDownload() { ...

How do I modify the date format displayed in the Bootstrap 4 datetimepicker when sending the value?

I have a datetimepicker() set with ID start_date that matches an input name. In the props, the format is specified as YYYY-MM-DD. I want to use this format for my API, but I want the user to see the date displayed in the format DD-MM-YYYY. $('#start_ ...

Struggles with incorporating OpenWeatherMap's response into my HTML document

My attempt to utilize the OpenWeatherMap API for showcasing specific items in HTML is not yielding the desired results. $('.`btn`').click(function() { var city = $('.inputValue').val(); var ...

vue form is returning empty objects rather than the actual input data

I am attempting to transfer data from my component to a view in order for the view to save the data in a JSON file. I have verified that the view is functioning correctly as I attempted to log the data in the component and found it to be empty, and the r ...

Can a jQuery/JavaScript script be run standalone?

I've got a bunch of HTML pages saved on my computer and I'm looking to create a JavaScript script that can extract specific text or elements from those pages. I found some jQuery code snippets on Stack Overflow that do what I need, but I'm n ...

How to convert a large whole number to an unsigned 8-bit integer in Python

I need to convert an array filled with signed 32-bit integers into an array containing unsigned integer values ranging from 0 to 255. My current code looks like this: newArray = Image.fromarray(oldArray.astype(numpy.uint8)) The issue is that I want the n ...

Similar to session_start() and $_SESSION in Node.js/Express

I'm on a quest to discover the equivalent of session_start() and $_SESSION in Node.js/Express so I can store the current user's id in the session. Most tutorials and videos recommend using express-session, but I've come across a warning: ...

overwriting result in nested foreach loops

Take a look at my PHP code snippet here: 1- In my HTML code, I have JavaScript content stored in the variable $content on line 2 2- My goal is to extract the JavaScript code into an array on line 17 3- There is also an array called $allowed_js which con ...