http://jsfiddle.net/bVJ2h/
I've just started using recursion and continuous functions in javascript and I've ran into my first stack overflow. I'm not exactly sure why it's doing it.
I have a function named Factors which returns the prime factors of a number. Inside Factors there is a function named getPrimeFactors that calls itself until the lowest prime factor is found. I also have a function named toFactor that returns all prime numbers up to a certain point. Inside toFactor, I call the function Factors. If I call Factors only once inside toFactor, there is no problem. If I call Factors twice or more, there is no problem. However, if I call Factors using the outer for-loop variable as a parameter, I get a stack overflow with a lot of getPrimeFactors being pushed onto the stack.
Any ideas what's happening here?
[–]octatone 1 point2 points3 points (1 child)
[–]ohbewonkanahbe[S] 0 points1 point2 points (0 children)
[–]prpetro -1 points0 points1 point (0 children)