Created
March 24, 2015 21:36
-
-
Save julienetie/d945889e6cb53f09f3a7 to your computer and use it in GitHub Desktop.
Sort Alphabetically
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
// 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