diff --git a/lib/query.js b/lib/query.js index 97358ba..ebc62b9 100644 --- a/lib/query.js +++ b/lib/query.js @@ -63,7 +63,20 @@ exports.operators = { } return items; }, - select: function(first){ + select: function(){ + var args = arguments; + return this.map(function(object){ + var selected = {}; + for(var i = 0; i < args.length; i++){ + var propertyName= args[i]; + if(object.hasOwnProperty(propertyName)){ + selected[propertyName] = object[propertyName]; + } + } + return selected; + }); + }, + values: function(first){ if(arguments.length == 1){ return this.map(function(object){ return object[first]; @@ -71,12 +84,10 @@ exports.operators = { } var args = arguments; return this.map(function(object){ - var selected = {}; + var selected = []; for(var i = 0; i < args.length; i++){ var propertyName= args[i]; - if(object.hasOwnProperty(propertyName)){ - selected[propertyName] = object[propertyName]; - } + selected.push(object[propertyName]); } return selected; }); @@ -189,7 +200,19 @@ exports.operators = { }), min: reducer(function(a, b){ return Math.min(a, b); - }) + }), + count: function(){ + return this.length; + }, + first: function(){ + return this[0]; + }, + one: function(){ + if(this.length > 1){ + throw new TypeError("More than one object found"); + } + return this[0]; + } }; exports.filter = filter; function filter(condition){