Skip to content

Instantly share code, notes, and snippets.

@davilima6
Last active April 30, 2019 08:43
Show Gist options
  • Save davilima6/d5145b723c3e58c09177e9afd62cc567 to your computer and use it in GitHub Desktop.
Save davilima6/d5145b723c3e58c09177e9afd62cc567 to your computer and use it in GitHub Desktop.
Haystack Exercise
haystack = "javascript"
needle1 = "jvs"
needle2 = "jts"
needle3 = "jvt"
def func(word, partial):
isFound = True
for char in haystack:
if not partial:
break
if partial[0] == char:
partial = partial[1:]
if partial:
isFound = False
return isFound
assert func(haystack, needle1) == True
assert func(haystack, needle2) == False
assert func(haystack, needle3) == True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment