Permalink
Browse files

implementation of the method Sum

Implementação do método Sum
  • Loading branch information...
1 parent 926c7a2 commit d08b31d2f5f577e42b67896d1288dd96a37ac6a5 @nielsenteixeira nielsenteixeira committed May 18, 2011
Showing with 11 additions and 0 deletions.
  1. +11 −0 lib/JSLINQ.js
View
@@ -172,6 +172,17 @@
},
LastOrDefault: function(defaultValue) {
return this.Last() || defaultValue;
+ },
+ Sum: function(clause){
+ var sum = 0;
+
+ for (var i = 0; i < this.items.length; i++) {
+ if (clause(this.items[i])) {
+ sum += clause(this.items[i]);
+ }
+ }
+
+ return this.items = sum;
}
};
})(this.window || exports, this.window === this ? "JSLINQ" : "Exec");

0 comments on commit d08b31d

Please sign in to comment.