Skip to content

Commit 26084eb

Browse files
author
Kyle Maune
committed
added ab check solution in ruby
1 parent 8e97976 commit 26084eb

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

Ruby Solutions/Easy/AB_check.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# AB_check.rb
2+
# splashinn
3+
4+
#Determine if two characters are separated a specific way in the string - return true if characters a and b are separated by exactly 3 places.
5+
def abCheck(str)
6+
return false if(str.include?('a') == false || str.include?('b') == false || str.rindex('b') < str.rindex('a'))
7+
return str.rindex('b') - str.rindex('a') == 4
8+
9+
end
10+
11+
p abCheck("bzzza") #false
12+
p abCheck("after badly") #false
13+
p abCheck("Laura sobs") #true
14+
p abCheck("aaaaddddd") #false

0 commit comments

Comments
 (0)