I have a recursive function for moving some circles on a canvas. Overed circle is enlarged (zoom in) and all the other circles is pushed away. Pushed circles push other circles
You don't need to know the number or operations needed for you to make an iterative solution. The point is to replace the JavaScript stack with one of your own. Check this answer to see an example how to implement it: Link
You can use an Array object as a stack in JavaScript since it supports push()
and pop()
.
PS: As Jim's answer suggested, you can usually find an algorithm that doesn't need this many levels of recursion.