From e7faf73834579ced447c77862857ef62e80d738b Mon Sep 17 00:00:00 2001 From: Andre Medeiros Date: Thu, 26 May 2022 18:17:49 -0400 Subject: [PATCH] sort scores --- internal/worker/trending.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/internal/worker/trending.go b/internal/worker/trending.go index 504b423..2629913 100644 --- a/internal/worker/trending.go +++ b/internal/worker/trending.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "os" + "sort" "strconv" "time" @@ -199,6 +200,10 @@ func (tc *trendingConsumer) Consume(delivery rmq.Delivery) { return } + sort.SliceStable(tps.Children, func(i, j int) bool { + return tps.Children[i].Score > tps.Children[j].Score + }) + posts := make([]string, tps.Count) for i, post := range tps.Children { posts[i] = fmt.Sprintf("%s: %d", post.Title, post.Score)