I have this array in javascript: you can see it here
Array
(
[2012-10-01] => Array
(
[1] => 1
[2] => 0
...
[148] => 0
[149] => 0
[150] => 1
)
[2012-10-02] => Array
(
[1] => 0
[2] => 1
...
[148] => 0
[149] => 1
[150] => 0
)
[2012-10-03] => Array
(
[1] => 1
[2] => 0
...
[148] => 0
[149] => 0
[150] => 1
)
..............
to reduce it, I want to keep only items whose have ones and omit the items with zeros. like this
Array
(
[2012-10-01] => Array
(
[23] => 1
[64] => 1
[70] => 1
[73] => 1
[76] => 1
[108] => 1
[138] => 1
)
I used underscorejs and this code:
var new_o={};
var v = _.each(original_array,function(day,key){
var arr = {};
_.map(day,function(item,k){
if (item){
arr[k]=item;
}
}) ;
new_o[key]= arr;
} ) ;
it works, but I am pretty sure, I didn't get the best of underscore. can anybody suggest a smarter way?