File tree Expand file tree Collapse file tree 3 files changed +25
-0
lines changed Expand file tree Collapse file tree 3 files changed +25
-0
lines changed Original file line number Diff line number Diff line change
1
+ -- Problem8
2
+ -- Eliminate consecutive duplicates of list elements.
3
+ -- If a list contains repeated elements they should be replaced with a single copy of the element.
4
+ -- The order of the elements should not be changed.
5
+
6
+ module Wiki_99_Questions.Problem8 where
7
+ import Data.List
8
+
9
+ compress :: Eq a => [a ] -> [a ]
10
+ compress = map head . group
Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ library
22
22
, Wiki_99_Questions.Problem5
23
23
, Wiki_99_Questions.Problem6
24
24
, Wiki_99_Questions.Problem7
25
+ , Wiki_99_Questions.Problem8
25
26
, Lib
26
27
build-depends : base >= 4.7 && < 5
27
28
default-language : Haskell2010
Original file line number Diff line number Diff line change
1
+ module Wiki_99_Questions.Problem8Spec where
2
+
3
+ import Test.Hspec
4
+ import Wiki_99_Questions.Problem8
5
+
6
+ spec :: Spec
7
+ spec = do
8
+ describe " Test1 for Problem8" $ do
9
+ it " compress \" aaaabbbccc\" -> \" abc\" " $ do
10
+ compress " aaaabbbccc" `shouldBe` " abc"
11
+
12
+ describe " Test2 for Problem9" $ do
13
+ it " compress \" Haskellllll\" -> \" Haskel\" " $ do
14
+ compress " Haskellllll" `shouldBe` " Haskel"
You can’t perform that action at this time.
0 commit comments