Add shortLenghts

This commit is contained in:
Pal Kerecsenyi 2024-05-08 10:55:59 +01:00
parent aeefdd2695
commit b40eaa948d
Signed by: palk
GPG Key ID: 6891661E25394C2C

11
short_lengths.hs Normal file
View File

@ -0,0 +1,11 @@
shortLengthsRecur :: [String] -> Int
shortLengthsRecur [] = 0
shortLengthsRecur (x : xs) = if l <= 5 then l + shortLengthsRecur xs else shortLengthsRecur xs
where
l = length x
shortLengthsListComp :: [String] -> Int
shortLengthsListComp i = sum [if length x <= 5 then length x else 0 | x <- i]
shortLengthsMapFilterFold :: [String] -> Int
shortLengthsMapFilterFold i = foldr (+) 0 (map length (filter (\e -> length e <= 5) i))