Skip to content

Instantly share code, notes, and snippets.

@julienba
Created March 5, 2011 22:18
Show Gist options
  • Save julienba/856773 to your computer and use it in GitHub Desktop.
Save julienba/856773 to your computer and use it in GitHub Desktop.
(function() {
(function(values, arg) {
var field, reverse;
field = arg[0];
reverse = arg[1];
return values.sort(function(a, b) {
var _ref;
if (reverse) {
_ref = [b, a], a = _ref[0], b = _ref[1];
}
if ((a != null ? a[field] : void 0) < (b != null ? b[field] : void 0)) {
return -1;
} else if ((a != null ? a[field] : void 0) === (b != null ? b[field] : void 0)) {
return 0;
} else if ((a != null ? a[field] : void 0) > (b != null ? b[field] : void 0)) {
return 1;
}
});
});
}).call(this);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment