Last active
August 29, 2015 14:15
-
-
Save shadoi/cb1f8f11a3fffb6fb0a3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Write a method that takes a string in and returns true if the letter | |
# "z" appears within three letters **after** an "a". You may assume | |
# that the string contains only lowercase letters. | |
# | |
# Difficulty: medium. | |
# may want to do max+1 as base-zero can be confusing | |
def x_after_y?(str, char1, char2, max) | |
range = Range.new(1, max) | |
str.slice!(str.chars.index(char1)) | |
if str.length > 0 | |
range.find {|n| true if str.chars.at(n) == char2} | |
end | |
end | |
--- | |
[7] pry(main)> x_after_y?('asdz', 'a', 'z', 3) | |
=> 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment