Created
July 26, 2010 21:55
-
-
Save ponzao/491319 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
(defn char-counter [str] | |
(reduce | |
(fn [m c] | |
(assoc m c (inc (get m c 0)))) | |
{} | |
str)) |
It seems I rewrote a core-function (frequencies).
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Character counter inspired by http://twoguysarguing.wordpress.com/2010/07/26/7-rules-for-writing-clojure-programs/. I knew there was a reduce solution, but I was too big of a noob to know what it was until I saw the Scala example.