---
title: "Discussion on \"JavaScript Sort() Method Principles, Use-Cases, and Tasks\" | Hashnode"
description: "Discussion on \"JavaScript Sort() Method Principles, Use-Cases, and Tasks\". Now you will understand sorting in JavaScript."
url: "https://hashnode.com/posts/javascript-sort-method-principles-use-cases-and-tasks/61284e9322e1ba252a8804af"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [JavaScript Sort() Method Principles, Use-Cases, and Tasks](https://unclebigbay.hashnode.dev/javascript-sort-method-principles-use-cases-and-tasks?utm_source=hashnode&utm_medium=feed)

Now you will understand sorting in JavaScript.

Aug 27, 2021 · 6 min read · unclebigbay.hashnode.dev  
Updated Aug 28, 2021  
Read the article

-   [#javascript](https://hashnode.com/tag/javascript)
-   [#explain-like-i-am-five](https://hashnode.com/tag/explain-like-i-am-five)
-   [#beginners](https://hashnode.com/tag/beginners)
-   [#developer-blogging](https://hashnode.com/tag/developer-blogging)
-   [#education](https://hashnode.com/tag/education)

## Written by

[Ayodele Samuel Adebayo](https://hashnode.com/@unclebigbay)

@unclebigbay · Nigeria

  
[View profile](https://hashnode.com/@unclebigbay)

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 &amp; Bug0

## Responses 6

Markdown supported · ⌘↵ to post

[Favourite Jome](https://hashnode.com/@Favourite)

[Aug 29, 2021](https://hashnode.com/posts/javascript-sort-method-principles-use-cases-and-tasks/61284e9322e1ba252a8804af/comment/612bcfca2858872661b9bf07)

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))
```

[Ayodele Samuel Adebayo](https://hashnode.com/@unclebigbay)

[Aug 29, 2021](https://hashnode.com/posts/javascript-sort-method-principles-use-cases-and-tasks/61284e9322e1ba252a8804af/comment/612bcfca2858872661b9bf07#reply-612bdc47fd0bf8636d76e45c)

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

[Yogesh Chavan](https://hashnode.com/@myogeshchavan97)

[Aug 28, 2021](https://hashnode.com/posts/javascript-sort-method-principles-use-cases-and-tasks/61284e9322e1ba252a8804af/comment/6129d0f02858872661b9896f)

Great overview of sort method [Ayodele Samuel Adebayo](https://hashnode.com/@unclebigbay)

[Ayodele Samuel Adebayo](https://hashnode.com/@unclebigbay)

[Aug 28, 2021](https://hashnode.com/posts/javascript-sort-method-principles-use-cases-and-tasks/61284e9322e1ba252a8804af/comment/6129d0f02858872661b9896f#reply-6129dc0afd0bf8636d76b043)

Glad the feedback is coming from you sir, thanks for checking it [Yogesh Chavan](https://hashnode.com/@myogeshchavan97)

[Idris Olubisi](https://hashnode.com/@olanetsoft)

[Aug 27, 2021](https://hashnode.com/posts/javascript-sort-method-principles-use-cases-and-tasks/61284e9322e1ba252a8804af/comment/612959da2858872661b981bd)

Brilliant Article Boss [Ayodele Samuel Adebayo](https://hashnode.com/@unclebigbay) i love the way you explained

[Ayodele Samuel Adebayo](https://hashnode.com/@unclebigbay)

[Aug 27, 2021](https://hashnode.com/posts/javascript-sort-method-principles-use-cases-and-tasks/61284e9322e1ba252a8804af/comment/612959da2858872661b981bd#reply-61295f99fd0bf8636d76a728)

Glad you liked it sir..

Happy it's coming from you 🤗

[Palash Mondal](https://hashnode.com/@iampalash)

[Aug 27, 2021](https://hashnode.com/posts/javascript-sort-method-principles-use-cases-and-tasks/61284e9322e1ba252a8804af/comment/6128a68071cb04254f06f0bb)

Nice one [Ayodele Samuel Adebayo](https://hashnode.com/@unclebigbay). 💜

For more Array `sort()` method use cases, you can check this out

[Top 7 JavaScript Array sort() Method Use Cases](https://iampalash.hashnode.dev/top-7-javascript-array-sort-method-use-cases).

[Ayodele Samuel Adebayo](https://hashnode.com/@unclebigbay)

[Aug 27, 2021](https://hashnode.com/posts/javascript-sort-method-principles-use-cases-and-tasks/61284e9322e1ba252a8804af/comment/6128a68071cb04254f06f0bb#reply-6128b33122e1ba252a8810cc)

Glad it's useful, and thanks for sharing more useful use-cases [Palash Mondal](https://hashnode.com/@iampalash) 🤗

checking them out 🏃‍♀️

[Ayodele Samuel Adebayo](https://hashnode.com/@unclebigbay)

[Aug 27, 2021](https://hashnode.com/posts/javascript-sort-method-principles-use-cases-and-tasks/61284e9322e1ba252a8804af/comment/6128a68071cb04254f06f0bb#reply-6128b4ad71cb04254f06f22d)

Your blog is really dope!!!

nice work in customizing it

[Palash Mondal](https://hashnode.com/@iampalash)

[Aug 27, 2021](https://hashnode.com/posts/javascript-sort-method-principles-use-cases-and-tasks/61284e9322e1ba252a8804af/comment/6128a68071cb04254f06f0bb#reply-6128cb529da1766342ad6097)

Glad you liked it [Ayodele Samuel Adebayo](https://hashnode.com/@unclebigbay) 🤩

[Eleftheria Batsou](https://hashnode.com/@eleftheriabatsou)

[Aug 27, 2021](https://hashnode.com/posts/javascript-sort-method-principles-use-cases-and-tasks/61284e9322e1ba252a8804af/comment/61288a8022e1ba252a880c57)

Nice work [Ayodele Samuel Adebayo](https://hashnode.com/@unclebigbay) :)

[Ayodele Samuel Adebayo](https://hashnode.com/@unclebigbay)

[Aug 27, 2021](https://hashnode.com/posts/javascript-sort-method-principles-use-cases-and-tasks/61284e9322e1ba252a8804af/comment/61288a8022e1ba252a880c57#reply-6128b2eb71cb04254f06f1f2)

Thanks a lot [Eleftheria Batsou](https://hashnode.com/@eleftheriabatsou)

Glad it's coming from you 💃💃💃

[Tapas Adhikary](https://hashnode.com/@atapas)

[Aug 27, 2021](https://hashnode.com/posts/javascript-sort-method-principles-use-cases-and-tasks/61284e9322e1ba252a8804af/comment/612880a022e1ba252a8809d3)

Nice refresher [Ayodele Samuel Adebayo](https://hashnode.com/@unclebigbay). Thanks for sharing.

[Ayodele Samuel Adebayo](https://hashnode.com/@unclebigbay)

[Aug 27, 2021](https://hashnode.com/posts/javascript-sort-method-principles-use-cases-and-tasks/61284e9322e1ba252a8804af/comment/612880a022e1ba252a8809d3#reply-612882ac71cb04254f06eb35)

Glad you liked it

Thanks for reading sir 🤗.
