question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Dynamic variable in for loop causes crash

See original GitHub issue

Challenge Name

Sum All Odd Fibonacci Numbers

https://www.freecodecamp.org/challenges/sum-all-odd-fibonacci-numbers

Issue Description

When entering in the parameter of the function as a variable in the for loop in the max place as shown below, it causes an endless loop and crashes the browser.

Browser Information

  • Chrome, Version: 61.0.3163.100
  • Operating System: MacOS Sierra 10.12.6
  • Mobile, Desktop, or Tablet: Desktop

Your Code

function sumFibs(num) {
  var fib = [1,1];
  
  for(var f=0;f<num;f++){
    var secondLast = fib.slice(-2);
    var last = fib.slice(-1);
    fib.push(secondLast[0] + last[0]);
  }
  return fib;
}

sumFibs(4);

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
IAmMyselfcommented, Oct 20, 2017

I believe that the problem here is that something handling the returned data is not expecting the array, not that the original loop itself is going on ad infinitum.

0reactions
QuincyLarsoncommented, Jun 3, 2018

I’m closing this issue as stale since it hasn’t been active lately. If you think this is still relevant to the newly updated platform, please explain why, then reopen it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

program crashing when trying to add to a dynamic array
You're using realloc incorrectly. You must accept the return value of realloc in a variable different from that used as the first parameter ......
Read more >
Program loop Crashes randomly - Arduino Forum
After some googling, I figured it might have something to do with dynamic memory allocation. So I brought the global variables from 15%...
Read more >
Scheduler enters crash loop in certain cases with dynamic ...
The scheduler does not crash and the dynamically mapped task executes ... installed Airflow 2.3.3, configured a few environment variables, ...
Read more >
Application crashes when changing static global variable
I am trying to change this variable dynamically on Xaml input change event, ... By the way you're right that's a dead loop,...
Read more >
Dynamic array of objects causes crash - c++ - Daniweb
Dynamic arrays work with objects, the problem is the value of the static variable Fuzzy::n. Destructors are only called if the memory is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found