Last active
April 30, 2019 08:43
-
-
Save davilima6/d5145b723c3e58c09177e9afd62cc567 to your computer and use it in GitHub Desktop.
Haystack Exercise
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
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