Skip to content

Instantly share code, notes, and snippets.

@ponzao
Created July 26, 2010 21:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ponzao/491319 to your computer and use it in GitHub Desktop.
Save ponzao/491319 to your computer and use it in GitHub Desktop.
(defn char-counter [str]
(reduce
(fn [m c]
(assoc m c (inc (get m c 0))))
{}
str))
@ponzao
Copy link
Author

ponzao commented Jul 26, 2010

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.

@ponzao
Copy link
Author

ponzao commented Jul 26, 2010

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