diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2020-10-09 23:32:06 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-10-09 23:32:06 +0100 |
| commit | d87f0d550ffdf399eb96ed12156c094e0f7fff64 (patch) | |
| tree | 25d5a05ff74198bdc01a61bed6cabab978dc83d0 | |
| parent | e9750be9af0e7868c6bc54ae2b2aeafcead6bfec (diff) | |
| parent | f5e4a7bc97c2642cf5cc3650a062c37bb8b4dbc7 (diff) | |
| download | perlweeklychallenge-club-d87f0d550ffdf399eb96ed12156c094e0f7fff64.tar.gz perlweeklychallenge-club-d87f0d550ffdf399eb96ed12156c094e0f7fff64.tar.bz2 perlweeklychallenge-club-d87f0d550ffdf399eb96ed12156c094e0f7fff64.zip | |
Merge pull request #2482 from tylerw/tw/challenge-081
Ch81/Task 2: optimize and add comments
| -rw-r--r-- | challenge-081/tyler-wardhaugh/clojure/src/tw/weekly/c81/t2.clj | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/challenge-081/tyler-wardhaugh/clojure/src/tw/weekly/c81/t2.clj b/challenge-081/tyler-wardhaugh/clojure/src/tw/weekly/c81/t2.clj index 543a1f54b6..c126e053b3 100644 --- a/challenge-081/tyler-wardhaugh/clojure/src/tw/weekly/c81/t2.clj +++ b/challenge-081/tyler-wardhaugh/clojure/src/tw/weekly/c81/t2.clj @@ -18,10 +18,10 @@ [source] (let [cleaner (fn [s] (str/replace s #"(?:[.\"\(\),]|'s|--|\n)" " ")) splitter (fn [s] (str/split s #" ")) - xf (comp (mapcat (comp splitter cleaner)) - (remove #{""}) - (x/by-key identity (x/into [])) - (x/by-key (comp count second) first (x/into (sorted-set))))] + xf (comp (mapcat (comp splitter cleaner)) ; wordify + (remove #{""}) ; discard empty strings + (x/by-key identity (constantly 1) (x/reduce +)) ; hash (word => count) + (x/by-key second first (x/into (sorted-set))))] ; invert hash, combine words (into (sorted-map) xf source))) (defn -main |
