Created
May 15, 2012 01:52
-
-
Save sj26/2698483 to your computer and use it in GitHub Desktop.
Easy key-based sorting in coffeescript with lower casing option
This file contains hidden or 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
cmp = (a, b) -> if a > b then 1 else if a < b then -1 else 0 | |
Array::sortBy = (key, options) -> | |
@sort (a, b) -> | |
[av, bv] = [a[key], b[key]] | |
[av, bv] = [av.toLowerCase(), bv.toLowerCase()] if options.lower | |
cmp av, bv |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you 👍, just what I was looking for!