Skip to content

Commit

Permalink
Added _sum and _count built-in functions
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-l committed Jul 23, 2015
1 parent d9a24f2 commit 84a7b94
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions lib/get_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,28 @@ module.exports = function (self) {
return false;
}

if (typeof view.reduce === 'string') {
switch (view.reduce) {
case '_sum':
/*jslint unparam:true*/
view.reduce = function (keys, values, rereduce) {
return values.reduce(function (a, b) { return a + b; });
};
/*jslint unparam:false*/
break;
case '_count':
/*jslint unparam:true*/
view.reduce = function (keys, values, rereduce) {
if (rereduce) {
return values.reduce(function (a, b) { return a + b; });
}
return values.length;
};
/*jslint unparam:false*/
break;
}
}

if (useReduce && !useGroup) {
// Reduce and no group
(function () {
Expand Down

0 comments on commit 84a7b94

Please sign in to comment.