Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialRoman Smolkin
969 PointsMaximum Call Stack Size Exceeded
It says to look at index.js for how it should work. So content and values are getting passed it, so I just update the content variable using the utilities.merge method right?
var utilities = require("./utilities"); function merge(content, values) { content = utilities.merge(content, values); return content; }
module.exports.merge = merge;
var utilities = require("./utilities");
var mailValues = {};
mailValues.first_name = "Janet";
var emailTemplate = "Hi %first_name%! Thanks for completing this code challenge :)";
var mergedContent = utilities.merge(emailTemplate, mailValues);
//mergedContent === "Hi Janet! Thanks for completing this code challenge :)";
var utilities = require("./utilities");
function merge(content, values) {
content = utilities.merge(content, values);
return content;
}
module.exports.merge = merge;
1 Answer
Steven Parker
231,248 PointsWhen a function calls itself without any kind of filtering condition, it creates a situation known as infinite recursion. This rapidly consumes the available memory on the stack.
Recursion is a useful technique, but is not always the best approach to a particular problem. And when it is, there must be a conditional expression to limit the recursion depth.
In this case, a simple loop would do a good job, similar to the example that was given in the video. You'll also need to add some code to perform the value substitution (also similar to what was done in the video).