Created
February 7, 2013 23:41
-
-
Save levicole/4735285 to your computer and use it in GitHub Desktop.
strstr
This file contains hidden or 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
def strstr(subject, search) | |
si = 0 | |
subject.length.times do |i| | |
if subject[i] == search[si] | |
if search.length == si + 1 | |
@found_at = i - si | |
break | |
end | |
si += 1 | |
else | |
si = 0 | |
end | |
end | |
puts @found_at | |
end | |
strstr("hello there", "her") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment