Skip to content

Instantly share code, notes, and snippets.

@orhanveli
Created September 23, 2020 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save orhanveli/0591f4ff99b4535e48eaaf90859d62c1 to your computer and use it in GitHub Desktop.
Save orhanveli/0591f4ff99b4535e48eaaf90859d62c1 to your computer and use it in GitHub Desktop.
The following recursive code will cause a stack overflow if the array list is too large. How can you fix this and still retain the recursive pattern?
var list = readHugeList();
var nextListItem = function() {
var item = list.pop();
if (item) {
// process the list item...
nextListItem();
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment