Open evantianx opened 6 years ago
countSmileys :: [String] -> Int
countSmileys = length . filter correct
correct [e,m] = e `elem` eyes && m `elem` mouth
correct [e,n,m] = n `elem` nose && correct [e,m]
correct _ = False
eyes = ":;"
nose = "-~"
mouth = ")D"
Given an array (arr) as an argument complete the function countSmileys that should return the total number of smiling faces.
Rules for a smiling face:
:
or;
-
or~
)
orD
. No additional characters are allowed except for those mentioned.Valid smiley face examples:
:) :D ;-D :~)
Invalid smiley faces:
;( :> :} :]
Example cases:
Note: In case of an empty array return 0. You will not be tested with invalid input (input will always be an array). Order of the face (eyes, nose, mouth) elements will always be the same