3 ms·
You're checking for a null local variable value in the third conditional, but appending to that same variable in the first two, which would either cause a runti
by AshFurrow 15y ago
You're checking for a null local variable value in the third conditional, but appending to that same variable in the first two, which would either cause a runtime error in most languages or never pass the third conditional.
- jpeterson 15y agoThis was my first thought as well. If he instead initializes: var result = ""; and checks for: if (result.length === 0) { ... in the third conditional, is there still a bug?
- AshFurrow 15y agoYes, he specifies the conditional is "examine the variable result; if it is still null ..."
- extension 15y agoIn Ruby, for example, you could append a string to nil by interpolating the nil into a string literal, or various other ways. Seeing as he didn't specify the language, what the variable was initialized to, or what exactly "append" means, we can only assume that these imaginary things behave as intended.