Extra #1 - dropWhile

Drop items from the start of a list until an item does not satisfy criteria specified by a function.

Example

dropWhile isEven [2, 4, 5, 6, 7] == [5, 6, 7]

Unit Test

import Html 
import List


dropWhile : (a -> Bool) -> List a -> List a
dropWhile predicate list =
    -- your implementation here
     list


main =
    Html.text
        (if (test) then
            "Your implementation passed all tests."
        else
            "Your implementation failed at least one test."
        )


test : Bool
test =
    List.all ((==) True)
        [ ( dropWhile isOdd [1, 2, 1] == [2, 1] )
        , ( dropWhile isEven [1, 2, 1] == [1, 2, 1] )
        , ( dropWhile isEven [] == [] )
        , ( dropWhile isEven [2, 4, 100000, 1] == [1] )
        , ( dropWhile (\x -> x < 5 ) (List.range 1 10) == [5, 6, 7, 8, 9, 10])
     ]


isEven x = x % 2 == 0
isOdd x = x % 2 /= 0

Hints

Recurse!

Solutions

Solutions

results matching ""

    No results matching ""