This naive algorithm compares two strings, needle
and haystack
. It returns true if haystack
"fuzzily" contains needle
, which is when (almost) every character in needle
is found in (almost) the same order, but not necessarily contiguously, in haystack
. Up to allowed_errors
characters in needle
are allowed to not be found in haystack
. Characters may also be swapped.
The following is a python implementation:
def stringFuzzilyContains(needle, haystack):
# allow this many characters to not be found
allowed_errors = 0
# the last index where a character was found;