Skip to content

Instantly share code, notes, and snippets.

@DanielVF
Created July 9, 2011 22:36
Show Gist options
  • Save DanielVF/1074014 to your computer and use it in GitHub Desktop.
Save DanielVF/1074014 to your computer and use it in GitHub Desktop.
Solving the Teleprompter coding kata in clojure
; 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