Ad
  • Default User Avatar

    its also difficult to understand ternary operators logic at first sight.

  • Default User Avatar

    I agree with the first comment, that this is no good practice. And I agree that if-else-if-constructs are also no good practice. But as you can see in the frist solution, the else is not even necessary. The result is very easy to read code. You haven't to be a programmer to understand that code. The point is you don't need to get used to it, but to chained ternary operators you have to.

  • Custom User Avatar

    Using chained ternary operators in a uniform way like here isn't bad practice either. It's very easy to grasp that the value literals are increasing upper bounds. Write the same as a chained if-else-if-construct has the advantage to be able to set breakpoints when debugging but also the disadvantage of a worse signal to noise ratio due to many ifs, elses and returns. I think the main reason people still prefer that even in simple cases like this one is that they're used to it. =)

  • Custom User Avatar

    Thanks for sharing this advice. I was thinking this was a clean way of doing it.

  • Default User Avatar

    Nested ternary operators are a hell to maintain. Not a good practice.

  • Custom User Avatar

    It's been years...but I will still fix it later today.

  • Default User Avatar

    The problem description stated "You cannot assume the size of the array". This solution will crash if the words and added spaces exceed 1000 characters.

  • Default User Avatar

    How do 8 kyus boost confidence?

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Default User Avatar

    Very fascinating problem to solve. Though I'm not sure the test cases are set up correctly, because my solution sometimes passed and sometimes didn't. The times that it didn't made no sense, for example the user ran out of money 1 year before his goal year so my code returned false, but the test expected true.

  • Default User Avatar

    Very easy problem to solve, good to boost your coding confidence so you cna jump back into the harder challenges.