Created
June 2, 2015 00:55
-
-
Save jbnv/f4bcc371b87f27fe7d92 to your computer and use it in GitHub Desktop.
Recency compare function (JavaScript)
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
// a, b: Date-time value (null if unknown or "never") | |
// altCompare: An alternative comparison function(a,b). | |
function recencyCompare(a,b) { | |
if (!a && !b) return altCompare(a,b); | |
if (!a) return 1; // 'b' has an error and 'a' doesn't | |
if (!b) return -1; // 'a' has an error and 'b' doesn't | |
if (a == b) { return altCompare(a,b); } | |
return a < b ? 1 : -1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment