The return statement:
return find(start + 5, "(" + history + " + 5)") ||
find(start * 3, "(" + history + " * 3)");
is an expression involving the "||" operator. That operator will cause the left-hand side to be evaluated. If the result of that is not null, zero, false
, or the empty string, then that value will be returned. If it is one of those "falsy" values, then the second expression is evaluated and returned.
In other words, that could be re-written like this:
var plusFive = find(start + 5, "(" + history + " + 5)");
if (plusFive !== null)
return plusFive;
return find(start * 3, "(" + history + " * 3)")
If "start" ever exceeds "goal", the function returns null. Of course, if both the alternatives don't work, then the whole thing will return null.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…