Skip to content

Instantly share code, notes, and snippets.

@WindSaber
WindSaber / SumByKey.js
Last active May 30, 2016 16:13 — forked from Cacodaimon/SumByKey.js
Fork of the original gist https://gist.github.com/Cacodaimon/7309268 with improvements (support fot objects Not ony arrays and floats instead of just int values)
angular.module('caco.feed.filter', [])
.filter('sumByKey', function() {
return function(data, key) {
if (typeof(data) === 'undefined' || typeof(key) === 'undefined') {
return 0;
}
var sum = 0;
angular.forEach(data, function(obj, objKey){
sum+= parseFloat(obj[key]);