From 147f28814283fbf0dfcac3347009ca610d01abf0 Mon Sep 17 00:00:00 2001 From: Sebastian Steger Date: Wed, 20 Aug 2025 15:11:10 +0200 Subject: [PATCH] list operations assignment --- haskell/02-list-operations/README.md | 10 ++++++++ haskell/02-list-operations/list-operations.hs | 23 +++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 haskell/02-list-operations/README.md create mode 100644 haskell/02-list-operations/list-operations.hs diff --git a/haskell/02-list-operations/README.md b/haskell/02-list-operations/README.md new file mode 100644 index 0000000..233237c --- /dev/null +++ b/haskell/02-list-operations/README.md @@ -0,0 +1,10 @@ +# Assignment + +You are provided with: + +1. A vector of names +2. A vector of ages + +Your task is to compute a list containing the UPPERCASE names of the two oldest persons whose names ends with an "a". The result shall be sorted by alphabet. + +Complete the corresponding unit test in the file `02-list-operations/list-operations.hs`. diff --git a/haskell/02-list-operations/list-operations.hs b/haskell/02-list-operations/list-operations.hs new file mode 100644 index 0000000..96aef07 --- /dev/null +++ b/haskell/02-list-operations/list-operations.hs @@ -0,0 +1,23 @@ +{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-} + +{-# HLINT ignore "Avoid reverse" #-} +{-# HLINT ignore "Use void" #-} + +import Data.Char (toUpper) +import Data.List (sort, sortOn) +import Test.HUnit + +names = ["Oliver", "Emma", "Liam", "Ava", "Noah", "Sophia", "James", "Mia", "Elijah", "Isabella"] + +ages = [25, 30, 22, 29, 35, 28, 40, 26, 33, 31] + +-- we are looking for the UPPERCASE names of the two oldest persons whose names ends with an a sorted alphabetically" + +extractedNames = [] + +test1 = Test.HUnit.TestCase (assertEqual "ExtractedNames" ["EMMA", "ISABELLA"] extractedNames) + +tests = TestList [test1] + +main :: IO () +main = runTestTT test1 >> return ()