groupBy('one', ['one']) does not work.
Closed this issue · 2 comments
makoto commented
Hello.
I was experimenting something and encountered an error. Wondering if this is an error, or rather a feature....
eg:
When there is a data set like this.
var ds = new Miso.Dataset({
data: [
{ one : 1, two : 4, three : 'a' },
{ one : 2, two : 5, three : 'b' },
{ one : 2, two : 8, three : 'c' }
]
});
This will work
ds.fetch({
success: function() {
log(this.groupBy('one', ['two'], {method:_.size}));
}
});
[{"_id":796,"_oids":[789],"one":1,"two":1},{"_id":797,"_oids":[790,791],"one":2,"two":2}]
However, selecting the grouped attribute does not work.
ds.fetch({
success: function() {
log(this.groupBy('one', ['one'], {method:_.size}));
}
});
Uncaught TypeError: Object 1 has no method 'push' (Raised at https://github.com/misoproject/dataset/blob/master/src/derived.js#L286)
The reason I am trying this is that I was trying to see if I can implement "countBy" just using "groupBy". If this is possible, "countBy" can be a simple wrapper of "groupBy"
alexgraul commented
It'd be possible to do (have countBy as a wrapper) but you end up littering groupBy with edge case code to handle it - I'd rather keep the codebase cleaner for now until we've got time to comprehensively refactor and work out whether there's an efficient and neat way of doing it.