DEV Community

Discussion on: Find longest word in a given string

Collapse
 
phallstrom profile image
Philip Hallstrom

Ignoring punctuation and only considering spaces... ruby solution:

def longest_word(str)
  str.split(/\s+/).max_by(&:length)
end