Skip to content

Instantly share code, notes, and snippets.

@IOIO72
Created May 10, 2019 08:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IOIO72/04cefe0a51cd9d05b0c83c01311f7f8d to your computer and use it in GitHub Desktop.
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.
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