function findSequence(goal) {
var find = function (start, history) {
if (start == goal)
return history;
else if (start > goal)
return null;
else
return find(start + 5, "(" + history + " + 5)") ||
find(start * 3, "(" + history + " * 3)");
}
return find(1, "1");
}
var sequence = findSequence(24);
Is sequence
a closure function? If yes, is this preferable to use closures in this way? I was taught by web resources to avoid closures.
UPDATE:
I was asked in the comments to show web resources. These are more reliable resources that i have seen in the web.
1.MDN - Closures under "Performance considerations".
2.Addy Osmani's Article under "Garbage Collection - Closures".
3.MSDN - see "Closures" section.
4.Stack Overflow Post - see accepted answer.
6.another intresting article - see last two paragraphs.