Created
July 9, 2011 22:36
-
-
Save DanielVF/1074014 to your computer and use it in GitHub Desktop.
Solving the Teleprompter coding kata in clojure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; Solving the Teleprompter coding kata in clojure | |
; (http://codingkata.org/katas/unit/teleprompter) | |
(defn de-slang [text dictionary] | |
(->> | |
(.split text "\\$") | |
(map (fn [word] [(str "\\$" word "\\$") (get dictionary word)])) | |
(filter (fn [word_set] (last word_set)) ) | |
(reduce (fn [str, word_set] (.replaceAll str (first word_set) (last word_set))) text)) ) | |
; Testing it | |
(def dictionary {"name" "nomenknocker", "Bob" "Frizizl", "I have" "i haz"}) | |
(def text "my $name$ is $Bob$ and $I have$ $50 cash." ) | |
(de-slang text dictionary ) | |
;> "my nomenknocker is Frizizl and i haz $50 cash." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment