Skip to content

Instantly share code, notes, and snippets.

Created June 18, 2014 07:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/3667d715788465b63874 to your computer and use it in GitHub Desktop.
Save anonymous/3667d715788465b63874 to your computer and use it in GitHub Desktop.
MyApp.filter 'orderObjectBy', () ->
return (items, fields, reverse) ->
filtered = []
angular.forEach items, (item, key) ->
filtered.push({key: key, value: item})
filtered.sort (a, b) ->
sifted_item_a = a
sifted_item_b = b
angular.forEach fields, (field) ->
sifted_item_a = sifted_item_a.value[field]
sifted_item_b = sifted_item_b.value[field]
return if sifted_item_a > sifted_item_b then 1 else -1
if reverse
filtered.reverse()
return filtered
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment