Skip to content

Instantly share code, notes, and snippets.

@sj26
Created May 15, 2012 01:52
Show Gist options
  • Save sj26/2698483 to your computer and use it in GitHub Desktop.
Save sj26/2698483 to your computer and use it in GitHub Desktop.
Easy key-based sorting in coffeescript with lower casing option
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
@danielfahy
Copy link

Thank you 👍, just what I was looking for!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment