Created
January 14, 2016 13:59
-
-
Save michaelpacker/a82d94cc04279dc70ed5 to your computer and use it in GitHub Desktop.
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
function sortResults(results, sortOrder, sortBy) { | |
var datePattern = /^\/Date\((\d*)\)\/$/; | |
var sortByString = String(results[0][sortBy]); | |
results.sort(function(a, b) { | |
if (sortBy) { | |
if (sortByString.match(datePattern)) { | |
var x = Healthx.convertJsonDateToDateObject(a[sortBy]); | |
var y = Healthx.convertJsonDateToDateObject(b[sortBy]); | |
} else { | |
var x = a[sortBy]; | |
var y = b[sortBy]; | |
} | |
} else { | |
var x = a; | |
var y = b; | |
} | |
if (typeof x == 'string') { | |
x = x.toLowerCase(); | |
y = y.toLowerCase(); | |
} | |
return ((x < y) ? -1 : ((x > y) ? 1 : 0)); | |
}); | |
if (sortOrder == 'descending') { | |
results.reverse(); | |
return results; | |
} else { | |
return results; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment