Skip to content

Instantly share code, notes, and snippets.

@zzz6519003
Forked from chenglou/anagram.cljs
Created November 29, 2015 14:19
Show Gist options
  • Save zzz6519003/922e8cfb967a0e17cfe1 to your computer and use it in GitHub Desktop.
Save zzz6519003/922e8cfb967a0e17cfe1 to your computer and use it in GitHub Desktop.
ClojureScript anagram implementation
; (group-by f list): call f on each item in list. The return value becomes a key
; of the resulting map, whose keys map to the list of items for which f returned
; that key.
; (vals map): returns a list of the values of the map.
(defn anagram [words] (vals (group-by sort words)))
(= (anagram ["star" "rats" "car" "arc" "stars"])
[["star" "rats"] ["car" "arc"] ["stars"]]) ; true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment