Add shortLenghts
This commit is contained in:
parent
aeefdd2695
commit
b40eaa948d
11
short_lengths.hs
Normal file
11
short_lengths.hs
Normal 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))
|
Loading…
x
Reference in New Issue
Block a user