practice-problems-1/comments/02-longest-word.rb
# Write a method that takes in a string. Return the longest word in
# the string. You may assume that the string contains only letters and
# spaces.
#
# You may use the String `split` method to aid you in your quest.
#
# Difficulty: easy.
Write a method that takes in a string. Return the longest word in
the string. You may assume that the string contains only letters and
spaces.

You may use the String `split` method to aid you in your quest.

easy.
Write a method that takes in a string . Return the longest word in the string . You may assume that the string contains only letters and spaces . You may use the String ` split ` method to aid you in your quest . easy .
def longest_word(sentence)
  longestWord = ""                            
  words = sentence.split(' ')                 
    words.each do |word|                      
      if  word.length > longestWord.length    
        longestWord =  word                   
      end
    end
    return longestWord                        
end
def longest_word ( sentence ) longestWord = "" words = sentence . split ( ' ' ) words . each do | word | if word . length > longestWord . length longestWord = word end end return longestWord end
Write a method that takes in a string.
Write a method that takes in a string .
#holds word #split sentence into array of words. #loop through array of words #if the word the loop is on is greater than the longest word..  #set the longest word to that word. #return longest word
sentence
<not_specific>