fork(1) download
  1. const f = new Function('',
  2. 'const recursiveFunction= (x) =>{' +
  3. 'if (x <= 0) return 0;' +
  4.  
  5. 'const value=recursiveFunction(x-1);' +
  6.  
  7. 'return 1 + value;' +
  8. '};' +
  9. 'return recursiveFunction(400);'
  10. );
  11.  
  12. const g = new Function('',
  13. 'const recursiveFunction= (x) =>{' +
  14. 'if (x <= 0) return 0;' +
  15.  
  16. 'const value=recursiveFunction(x-1);' +
  17.  
  18. 'return 1 + value;' +
  19. '};' +
  20. 'return recursiveFunction(500);'
  21. )
  22.  
  23. var stack = [1000000];
  24.  
  25. var y = 0;
  26.  
  27. while (stack.length){
  28. let x = stack.pop();
  29.  
  30. if (x == 0){
  31. print('Stack result for 1,000,000: ' + y);
  32. continue;
  33. }
  34.  
  35. y = y + 1;
  36. stack.push(x - 1);
  37. }
  38.  
  39. print('Recursive result for 400: ' + f());
  40. print('Recursive result for 500: ' + g()); // Oops... "prog.js:5:0 InternalError: too much recursion"
Runtime error #stdin #stdout #stderr 0.31s 12132KB
stdin
Standard input is empty
stdout
Stack result for 1,000,000: 1000000
Recursive result for 400: 400
stderr
prog.js:13:0 InternalError: too much recursion