Python Recursive Function Global Variable Javascript