Skip to content

Instantly share code, notes, and snippets.

@mahmoud-samy
Created August 28, 2016 14:56
Show Gist options
  • Save mahmoud-samy/7e8826d8d68c29263f6f7e8ce84ac866 to your computer and use it in GitHub Desktop.
Save mahmoud-samy/7e8826d8d68c29263f6f7e8ce84ac866 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