DEV Community

Discussion on: No duplicates challenge in Elm

antonrich profile image
Anton Author

How do I pattern match on the list with two elements?

noDupes : List a -> List a
noDupes list =
    case list of
        [] -> []
        x::y ->
            if x == y then
                x :: list
                x :: y :: list
        x::y::xs ->
            if x == y then
                x :: noDupes xs
                x :: (noDupes y::xs)

And in the case of two element how do you add that to the rest of the list? As you can see I use "list" in the second case. I don't think it's correct.