Skip to content

Instantly share code, notes, and snippets.

@killtw
Last active December 17, 2015 18:59
Show Gist options
  • Save killtw/5657102 to your computer and use it in GitHub Desktop.
Save killtw/5657102 to your computer and use it in GitHub Desktop.
sort object by key
ksort = (obj, method=true) ->
keys = for key of obj
key
if method then keys.sort() else keys.reverse()
new_obj = {}
new_obj[key] = obj[key] for key in keys
new_obj
ksort(obj)
ksort(obj, false) # reverse
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment