Closed firezdog closed 5 years ago
Note -- just realized that the returns need to evaluate both expressions on the left and right side of the operator -- that change being made, this solution also seems to work, give or take a few edge cases like + 1 1 1 (which I don't consider to be correctly formed because I think '+' is a binary operator)
i.e.
...
return evaluate(t->children[i+1]) + evalute(t->children[i+2])
Yeah, the interpretation is up to you so I think this is a good a solution as any if it produces the behaviour you think is right 👍
I was working through this and came up with a rather different solution -- I don't think the algorithm, if that's the right word to describe it, is quite the same? Any thoughts on this in terms of best practices? I think yours is definitely much nicer to read...