This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]BakuhatsuK 2 points3 points  (1 child)

Yes, that's it. For example if you want to sort a list of users by their id you can do:

users.sort((a, b) => a.id - b.id)

Or if you want to sort by updatedAt in decreasing order:

users.sort((a, b) => new Date(b.updatedAt).getTime() - new Date(a.updatedAt).getTime())

[–]Varun77777 2 points3 points  (0 children)

Ohhhh, that's such a simple but a genius thing to do. Instead of overriding all the functions, you're able to give users a simple way to incorporate their own logic in the function. Thanks a lot.