-
Notifications
You must be signed in to change notification settings - Fork 1
/
P31745.hs
29 lines (25 loc) · 1.62 KB
/
P31745.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
------------------------------------------------------------------------------------
------------------------------------- FLATTEN --------------------------------------
------------------------------------------------------------------------------------
flatten :: [[Int]] -> [Int]
flatten array = foldr (++) [] array
------------------------------------------------------------------------------------
------------------------------------- MYLENGTH -------------------------------------
------------------------------------------------------------------------------------
myLength :: String -> Int
myLength text = sum $ map (const 1) text
------------------------------------------------------------------------------------
------------------------------------- MYREVERSE ------------------------------------
------------------------------------------------------------------------------------
myReverse :: [Int] -> [Int]
myReverse array = foldl (flip (:)) [] array
------------------------------------------------------------------------------------
-------------------------------------- COUNTIN -------------------------------------
------------------------------------------------------------------------------------
countIn :: [[Int]] -> Int -> [Int]
countIn l x = map (length) $ map (filter (== x)) l
------------------------------------------------------------------------------------
------------------------------------- FIRSTWORD ------------------------------------
------------------------------------------------------------------------------------
firstWord :: String -> String
firstWord text = takeWhile (/= ' ') $ dropWhile (== ' ') text