Skip to content

Instantly share code, notes, and snippets.

@B-Stefan
Created September 15, 2014 19:54
Show Gist options
  • Save B-Stefan/c43dde55c17aa1355b07 to your computer and use it in GitHub Desktop.
Save B-Stefan/c43dde55c17aa1355b07 to your computer and use it in GitHub Desktop.
Angular sum filter for tables
define ['./filters'], (filters)->
filters.filter 'sumByKey', [-> (data, key) ->
return 0 if typeof (data) is "undefined" or typeof (key) is "undefined"
sum = 0
i = data.length - 1
while i >= 0
sum += parseInt(data[i][key])
i--
sum
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment