You can turn the given code into a one-liner by using the ternary operator. Here's the one-liner version:
main.rb77 chars4 lines
The ternary operator is used to conditionally return different values based on the given conditions. In this case, if the number n
is divisible by 105, it returns 'pg', if it's divisible by 15, it returns 'plg', and otherwise, it returns n
converted to a string.
This one-liner code simplifies the original function while maintaining the same logic.
gistlibby LogSnag