Dynamic variable in for loop causes crash
See original GitHub issueChallenge 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:
- Created 6 years ago
- Comments:9 (5 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
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.