Permalink
Browse files

Merge pull request #6 from nielsenteixeira/master

Method Sum
  • Loading branch information...
2 parents 926c7a2 + d08b31d commit 5d4c1499b88608c213355ffcb418b7c9a359d9ec @Marak committed May 19, 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 5d4c149

Please sign in to comment.