Well-done Favourite.
I understand what you're saying
But here's the problem we're trying to solve.
Imagine I have 2 likes and 3 comments on my blog post for today
You on the other end have 10 likes and 2 comments
Someone else is having 2 likes and 3 comments as me
Since we're sorting based on the blog post that has the most interactions
Hint π
(a.likes + a.comments)
I hope this helps
Let me know if this helps
Nicely written UBB, I don't know if I'm correct, in your formula you wrote likes + comments, but I couldn't sort but likes and comments without breaking one.
So I only checked for likes...
const descendingLikes = (array) => { return array.sort((a, b) => { return a.likes - b.likes }); }; const ascendingLikes = (array) => { return array.sort((a, b) => { return b.likes - a.likes; }); }; console.log(descendingLikes(blogPosts)) console.log(ascendingLikes(blogPosts))