Skip to content

Commit

Permalink
feat(sum): create sum filter
Browse files Browse the repository at this point in the history
  • Loading branch information
a8m committed Aug 30, 2014
1 parent c076bae commit 8fd7480
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/_filter/math/sum.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* @ngdoc filter
* @name sum
* @kind function
*
* @description
* Sum up all values within an array
*
*/

angular.module('a8m.math.sum', [])

.filter('sum', function () {
return function (input, initial) {

return (!isArray(input)) ? input :
input.reduce(function(prev, curr) {
return prev + curr;
}, initial || 0);

}

});

0 comments on commit 8fd7480

Please sign in to comment.