Algorithm removes vowels, unexpected result

Viewed 125

I am trying to build an algorithm that removes the vowels from a string. The below code is what I have so far.

def shortcut(s)
  s = s.split("")
  for i in 0..s.length - 1 do
    if ["a","e","i","o","u"].include?(s[i])
      s.delete_at(i)
    end
  end
  s.join
end


puts shortcut("hello world, we are the champions")
# => hll wrld, w r th chmpons

Why is the 'o' not being removed from the string?

7 Answers
Related