Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/perliedman/trivial-compare
Simplest possible JavaScript comparison function, as a module
https://github.com/perliedman/trivial-compare
Last synced: about 1 month ago
JSON representation
Simplest possible JavaScript comparison function, as a module
- Host: GitHub
- URL: https://github.com/perliedman/trivial-compare
- Owner: perliedman
- Created: 2021-09-29T13:05:30.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2021-09-29T13:22:05.000Z (about 3 years ago)
- Last Synced: 2024-09-18T14:13:38.585Z (about 2 months ago)
- Language: JavaScript
- Size: 1.95 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
trivial-compare
===============The simplest possible compare function that can be used with JavaScript's `Array.prototype.sort`
and any data type that gives reasonable results for the `<` and `>` comparison operators.In practice, this means you can use this library to sort numbers as well as strings without caring
what the elements actually are.I find myself dropping this tiny utility function in more or less any app I write, so now there's
a stupid npm module to stop this madness.(As an aside, it feels weird such a function would not be part of the standard library - I sort of
hope this is a misunderstanding on my part and this library is just totally redundant, please drop
me a note if there's a better way to do this!)## API
There's just a single function exported by this library:
`compare(a, b)`
`comapare` will return `-1` if `a < b`, `1` if `a > b` and `0` otherwise (if they are equal, in other words).