Created
December 6, 2010 07:18
-
-
Save rachelmyers/729977 to your computer and use it in GitHub Desktop.
white. boards. suck.
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
def substring(haystack, needle) | |
i = 0 | |
while i <= haystack.length | |
if haystack[i,(needle.length)] == needle | |
return i | |
else | |
i += 1 | |
end | |
if i == haystack.length | |
return nil | |
end | |
end | |
end | |
puts substring("stupid", "smart") | |
puts substring("stupid", "stu") | |
puts substring("stupid", "pid") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment