Last active
May 28, 2016 12:56
-
-
Save dasibre/f7228ac332b6a2a9b1f613c1a94ca06a to your computer and use it in GitHub Desktop.
name-score-problem
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 accum1 | |
[h pair-arry] | |
(if (contains? h (get pair-arry 1)) | |
(merge-with conj h (hash-map (get pair-arry 1) (get pair-arry 0))) | |
(merge-with conj h (hash-map (get pair-arry 1) [(get pair-arry 0)])))) | |
;; short version of accum | |
(defn accum2 | |
[h pair-arry] | |
(merge-with conj h (hash-map (keyword (get pair-arry 1)) (if (contains? h (keyword (get pair-arry 1))) (get pair-arry 0) [(get pair-arry 0)])))) | |
(defn name-score [str-arry] | |
(reduce accum2 {} (map #(clojure.string/split % #":") str-arry))) | |
(name-score (clojure.string/split "john:1,jane:1,joy:2" #",")) ;;{:1 ["john" "jane"], :2 ["joy"]} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment