Skip to content

Commit

Permalink
Added values, count, first, and one methods
Browse files Browse the repository at this point in the history
  • Loading branch information
kriszyp committed Jul 6, 2010
1 parent 9498d7e commit a952690
Showing 1 changed file with 29 additions and 6 deletions.
35 changes: 29 additions & 6 deletions lib/query.js
Expand Up @@ -63,20 +63,31 @@ 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];
});
}
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;
});
Expand Down Expand Up @@ -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){
Expand Down

0 comments on commit a952690

Please sign in to comment.