simple-exercises/ruby-exercises/easy-5.rb
# For F's Sake
# ------------------------------------------------------------------------------
# Given a string, return the word that has the letter "f" closest to
# the end of it.  If there's a tie, return the earlier word.  Ignore punctuation.
#
# If there's no f, return an empty string.
# ------------------------------------------------------------------------------
For F's Sake
Given a string, return the word that has the letter "f" closest to
the end of it.  If there's a tie, return the earlier word.  Ignore punctuation.

If there's no f, return an empty string.
For F ' s Sake Given a string return the word that has the letter " f " closest to the end of it . If there ' s a tie return the earlier word . Ignore punctuation . If there ' s no f return an empty string .
def for_fs_sake(string)
  words = string.split(" ")
  the_word = ""
  f_index = nil 
  words.each do |word|
    (1..word.length).each do |i|
      if word[-i] == "f"
        if the_word == "" or i < f_index
          the_word = word
          f_index = i
          break
        end
      end
    end
  end
  the_word
end
def for_fs_sake ( string ) words = string . split ( " " ) the_word = "" f_index = nil words . each do | word | ( 1 .. word . length ) . each do | i | if word [ - i ] == "f" if the_word == "" or i < f_index the_word = word f_index = i break end end end end the_word end
For F's Sake
Given a string, return the word that has the letter "f" closest to
the end of it.
For F ' s Sake Given a string return the word that has the letter " f " closest to the end of it .
# index from end #find an f
string
<not_specific>