Software Engineer | Open-Source Contributor | Developer Educator
Software engineer and developer educator with over four years of experience building production-grade digital products for platforms serving millions of developers globally. Software engineer at Hashnode & Bug0
Markdown supported Β· ββ΅ to post
Nice one Ayodele Samuel Adebayo. π
For more Array sort() method use cases, you can check this out
Ayodele Samuel Adebayo
Ayodele Samuel Adebayo
Ayodele Samuel Adebayo
Favourite Jome
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))