Sort hits

This commit is contained in:
Jeremy Dormitzer 2018-01-10 08:22:08 -05:00
parent 9826d49e34
commit 8766d0c86e
No known key found for this signature in database
GPG Key ID: 04F17C0F5A32C320

View File

@ -26,6 +26,11 @@
(let [{:strs [hits]} response]
(filter #(= (get % "url") url) hits)))
(defn sort-hits
"Sorts hits from hn.algolia.com by post date descending"
[hits]
(sort-by #(get % "created_at_i") #(compare %2 %1) hits))
(defn total-num-comments
"Returns the total number of comments from some hits"
[hits]
@ -42,4 +47,7 @@
(let [current-url (-> js/window (.-location) (.-href))
sub-chan (fetch-submission current-url)]
(go (handle-hits (filter-response current-url (<! sub-chan)))))
(go (->> (<! sub-chan)
(filter-response current-url)
(sort-hits)
(handle-hits))))