Skip to content

Ch11: isSubsequenceOf function is incorrect #4

Closed
@Bassov

Description

@Bassov

isSubsequenceOf :: Eq a => [a] -> [a] -> Bool

Hi! There is a problem in a function, if we eval isSubsequenceOf "bl" "baaal" it would return True.

I've solve this task like this:

isSubsequenceOf :: Eq a => [a] -> [a] -> Bool
isSubsequenceOf xs ys = go xs ys
    where
        go [] _          = True
        go _ []          = False
        go (a:as) (b:bs) = (a == b && go as bs) || go xs bs

So I haven't found usage for xs@(x:_) syntax in this task:(

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions