JavaScript recursion: Maximum call stack size exceeded

前端 未结 4 806
醉话见心
醉话见心 2021-02-13 02:29

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

4条回答
  •  北恋
    北恋 (楼主)
    2021-02-13 02:57

    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.

提交回复
热议问题