longest word _ regex

Submitted over 2 years Ago

def longest_word(sentence) longest_word = "" sentence.scan(/\w+/).each do |word| longest_word = word if word.length > longest_word.length end return longest_word end

0 Comments