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?
Code:
var list = readHugeList();
var nextListItem = function() {
var item = list.pop();
if (item) {
// process the list item...
nextListItem();
}
};
Comment