Everything seems to work just fine, except for the commented line:
#return false if not s[0].upcase =~ /AZ/
and the fourth check.
What is the correct operator ifto compare s[0]and /AZ/?
def starts_with_consonant?(s)
return false if s.length == 0
#return false if not s[0].upcase =~ /AZ/
n = "AEIOU"
m = s[0]
return true if not n.include? m.upcase
false
end
puts starts_with_consonant?("Artyom") # false 1
puts starts_with_consonant?("rtyom") # true 2
puts starts_with_consonant?("artyom") # false 3
puts starts_with_consonant?("$rtyom") # false 4
puts starts_with_consonant?("") # false 5
source
share