the question is pretty similar to this thread Javascript..totally lost in this tutorial.
function findSequence(goal) {
function find(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");
}
print(findSequence(24));
I got stuck at this part :
find(start * 3, "(" + history + " * 3)");
each time start goes beyond goal what does it do? it says it return null but when I test and put breakpoint on
if (start == goal) it shoes this on the console
history: "(((((1 + 5) + 5) + 5) + 5) + 5)"
start: 26
history: "(((((1 + 5) + 5) + 5) + 5) * 3)"
start: 63
it add up *3 and take off +5, I don't understand how.
See Question&Answers more detail:os