documentcloud/underscore — Issue #359: Filtering on objects could return an object
Author: chikamichi
Created: 2011-11-01 13:31:46+00:00
State: open

Hi,

Here is a common use-case for filter. Given

``` js
a = {35: true, 45: true, 55: false}
```

one would like to filter and get back only pairs which value is truish:

``` js
_.filter(a, function(val, key) {
val === true;
});
// => {35: true, 45: true}
```

Currently, functions such as filter push(value) so one gets an array.

Is there any easy way to achieve this with a workaround, and if not, would you consider switching the return's type based on whether we're providing an object or a list?