Skip to content

Instantly share code, notes, and snippets.

@julienetie
Created March 24, 2015 21:36
Show Gist options
  • Save julienetie/d945889e6cb53f09f3a7 to your computer and use it in GitHub Desktop.
Save julienetie/d945889e6cb53f09f3a7 to your computer and use it in GitHub Desktop.
Sort Alphabetically
// Sort Alphabetically
Array.prototype.sortAlphabetically = function (direction) {
var _this = this;
function comparator(a, b) {
if (direction < 0) {
return a == b ? 0 : a < b ? 1 : -1;
} else {
return a == b ? 0 : a < b ? -1 : 1;
}
}
return _this.sort(comparator);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment