Created
May 10, 2019 08:26
-
-
Save IOIO72/04cefe0a51cd9d05b0c83c01311f7f8d to your computer and use it in GitHub Desktop.
Compares two values and returns the sort direction for the sort() function. Use the `order` parameter with one of the values `1` or `-1` to change sort direction.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const sortCompare = (a, b, order = 1) => { | |
if (a > b) return order; | |
if (a < b) return order * -1; | |
return 0; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment