I\'m trying to create method named longest_word that takes a sentence as an argument and The function will return the longest word of the sentence.
longest_word
My c
Funcional Style Version
str.split(' ').reduce { |r, w| w.length > r.length ? w : r }
Another solution using max
str.split(' ').max { |a, b| a.length <=> b.length }