Skip to content

Instantly share code, notes, and snippets.

@jbnv
Created June 2, 2015 00:55
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 jbnv/f4bcc371b87f27fe7d92 to your computer and use it in GitHub Desktop.
Save jbnv/f4bcc371b87f27fe7d92 to your computer and use it in GitHub Desktop.
Recency compare function (JavaScript)
// 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