当 str[0] 是 "a" 并且 str[4] 是 "b" 时,我得到了正确的结果。但是,当“a”在另一个位置并且与“b”隔开三个空格时,我会出错。
任何帮助都会很棒!
def ABCheck(str)
str.downcase.split()
x = 0
while x < str.length - 4
return true if ((str[x] == "a") && (str[x + 4] =="b"))
x += 1
return false
end
end
puts ABCheck("azzzb")
#Currently puts "true"
puts ABCheck("bzzabzcb")
#Currently puts "false" - even though it should print true
Run Code Online (Sandbox Code Playgroud)