shorten: `def con(n) return 'pg' if (n % 105).zero? return 'plg' if (n % 15).zero? return n.to_s end` in ruby

You can shorten the provided code using a conditional operator and string interpolation. Here's the shorter version:

main.rb
def con(n)
  return 'pg' if (n % 105).zero?
  return 'plg' if (n % 15).zero?
  n.to_s
end
90 chars
6 lines

In the shortened version, the return keyword is removed from each line since the last expression evaluated in a method is automatically returned. Additionally, we can use string interpolation (#{}) instead of explicitly converting n to a string using n.to_s.

Let me know if you need any further assistance!

related categories

gistlibby LogSnag