Skip to content

Commit f36a524

Browse files
committed
Solve 'Removing Elements' kata
1 parent 8df5d6c commit f36a524

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/Removing.hs

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module Removing (removeEveryOther) where
2+
3+
-- https://www.codewars.com/kata/5769b3802ae6f8e4890009d2/train/haskell
4+
5+
removeEveryOther :: [a] -> [a]
6+
removeEveryOther [] = []
7+
removeEveryOther [x] = [x]
8+
removeEveryOther (x:xs) = (x :) . removeEveryOther . tail $ xs

test/RemovingSpec.hs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module RemovingSpec where
2+
3+
import Removing (removeEveryOther)
4+
import Test.Hspec
5+
6+
spec :: Spec
7+
spec = do
8+
it "Fixed Tests" $ do
9+
removeEveryOther ["Hello", "Goodbye", "Hello Again"]
10+
`shouldBe` ["Hello", "Hello Again"]
11+
removeEveryOther [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
12+
`shouldBe` [1, 3, 5, 7, 9]
13+
removeEveryOther [[1, 2]]
14+
`shouldBe` [[1, 2]]
15+
removeEveryOther [Left "Goodbye", Right ("Great", "Job")]
16+
`shouldBe` [Left "Goodbye"]

0 commit comments

Comments
 (0)