To fix the given code and keep it short using ternaries, you can rewrite it as follows:
main.rb139 chars8 lines
In this solution, we removed the nested ternaries and used multiple if
conditions with string concatenation. We check each condition separately and append the corresponding string to r
if the condition is true. Finally, we return r
if it's not empty, otherwise, we return n
converted to a string.
This approach still provides the expected behavior while being easier to read and understand.
gistlibby LogSnag