Created
September 7, 2015 12:09
-
-
Save joemaidman/dd669b6743e140a18442 to your computer and use it in GitHub Desktop.
Javascript sort functions
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
//Sort values ascending | |
function compareByValueAsc(a, b) { | |
if (a.value < b.value) | |
return -1; | |
if (a.value > b.value) | |
return 1; | |
return 0; | |
} | |
//Sort values descending | |
function compareByValueDes(a, b) { | |
if (a.value > b.value) | |
return -1; | |
if (a.value < b.value) | |
return 1; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment