-
Notifications
You must be signed in to change notification settings - Fork 14
/
Deletion.elm
39 lines (30 loc) · 900 Bytes
/
Deletion.elm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
module Challenge.Deletion exposing (deletion)
import Challenge exposing (Challenge)
import Fuzz
import Test exposing (Test)
deletion : Challenge ( List Int, Int )
deletion =
{ label = "deletion"
, fuzzer =
Fuzz.listOfLengthBetween 1 100 Fuzz.int
|> Fuzz.andThen
(\list ->
Fuzz.pair
(Fuzz.constant list)
(Fuzz.oneOfValues list)
)
, test = \( list, el ) -> not (List.member el (removeFirst el list))
}
removeFirst : a -> List a -> List a
removeFirst badX xs =
go badX xs [] xs
go : a -> List a -> List a -> List a -> List a
go badX next prev orig =
case next of
[] ->
orig
x :: rest ->
if x == badX then
List.reverse prev ++ rest
else
go badX rest (x :: prev) orig