summaryrefslogtreecommitdiff
path: root/5-kyu/hashtag-generator.hs
diff options
context:
space:
mode:
authorMistivia <i@mistivia.com>2025-04-24 02:46:39 +0800
committerMistivia <i@mistivia.com>2025-04-24 02:46:39 +0800
commit2a9e59907868d12a2a3ea387ec90074e26cc90c3 (patch)
tree8bc367c09ab4e1967481fd97abf1e29a81f62b04 /5-kyu/hashtag-generator.hs
init
Diffstat (limited to '5-kyu/hashtag-generator.hs')
-rw-r--r--5-kyu/hashtag-generator.hs24
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