diff options
| author | Mistivia <i@mistivia.com> | 2025-04-24 02:46:39 +0800 |
|---|---|---|
| committer | Mistivia <i@mistivia.com> | 2025-04-24 02:46:39 +0800 |
| commit | 2a9e59907868d12a2a3ea387ec90074e26cc90c3 (patch) | |
| tree | 8bc367c09ab4e1967481fd97abf1e29a81f62b04 /5-kyu/hashtag-generator.hs | |
init
Diffstat (limited to '5-kyu/hashtag-generator.hs')
| -rw-r--r-- | 5-kyu/hashtag-generator.hs | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/5-kyu/hashtag-generator.hs b/5-kyu/hashtag-generator.hs new file mode 100644 index 0000000..2da598f --- /dev/null +++ b/5-kyu/hashtag-generator.hs @@ -0,0 +1,24 @@ +-- https://www.codewars.com/kata/52449b062fb80683ec000024 + +module Codewars.Kata.Hashtag where + +import Data.Char +import Control.Monad + +capitalized w = (toUpper $ head w) : (map toLower $ tail w) + +processCapChar s = + join $ map (\x -> if isLower x then [x] else " "++[x]) s + +generateHashtag :: String -> Maybe String +generateHashtag s = impl (processCapChar s) + where + impl s + | length (words s) == 0 = Nothing + | otherwise = + let result = "#" ++ (join $ map capitalized $ words s) + in + if (length result) > 140 then + Nothing + else + Just result |
