From 8766d0c86e1f3a9de90fa00d1b072600aa758f34 Mon Sep 17 00:00:00 2001 From: Jeremy Dormitzer Date: Wed, 10 Jan 2018 08:22:08 -0500 Subject: [PATCH] Sort hits --- src/content/looped_in/content.cljs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/content/looped_in/content.cljs b/src/content/looped_in/content.cljs index a20d8c7..de00c1c 100644 --- a/src/content/looped_in/content.cljs +++ b/src/content/looped_in/content.cljs @@ -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 (> (