Skip to content

Instantly share code, notes, and snippets.

@rachelmyers
Created December 6, 2010 07:18
Show Gist options
  • Save rachelmyers/729977 to your computer and use it in GitHub Desktop.
Save rachelmyers/729977 to your computer and use it in GitHub Desktop.
white. boards. suck.
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