Getting unexpected "end"

Where am i putting the extra “end?”

def abbreviate_sentence(sent)
words = sent.split(" “)
new_words = []
vowels = “aeiou”
words.each do |word|
if word.length < 4
new_words << word
end
words.each do |word|
word.each do |char|
if !vowels.include?(char)
new_words += char
end
end
return new_words.join(” ")
end

Where am i putting the extra “end?”

If anything, there are two too few ‘ends’.

Maybe you need to end the two ‘do’ expressions? e.g. see commented ‘ends’:

def abbreviate_sentence(sent)
  words = sent.split(" ")
  new_words = []
  vowels = "aeiou"
  words.each do |word|
    if word.length < 4
      new_words << word
    end
  end # added
  words.each do |word|
    word.each do |char|
      if !vowels.include?(char)
        new_words += char
      end
    end
  end # added
  return new_words.join(" ")
end

BTW, I have no idea what you want the function to do. If you describe it, I can help you put the ‘ends’ in the right place. (You have two lots of words.each do |word| ...)

Problem:
Write a method abbreviate_sentence that takes in a sentence string and returns a new sentence where every word longer than 4 characters has all of it’s vowels removed.puts

puts abbreviate_sentence(“follow the yellow brick road”) # => “fllw the yllw brck road”
puts abbreviate_sentence(“what a wonderful life”) # => “what a wndrfl life”

The answer in the tutorial calls for a helper method. Where i make a method that abbreviates the word. I wanted to cut that step out.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs