javascript - Filtering objects in underscore -


i'm trying create filterobject mixin in underscore. it's not going quite well, there i'm missing?

_.mixin({   filterobject: function(collection, fn){     var n = []     _.each(collection, function(value, key){       var decider = fn(value, key)       if(decider){         var temp = {}         temp[key] = value         n.push(temp)       }     })     return _.extend.apply(null, n);   } })  var actionsflags = {   "wallpaper": {     "images": true,     "queue": false,   },   "notify":{     "message": true,     "open": true,     "queue": false,   }, }  var requiredflags = _.filterobject(actionsflags, function(flags){   return _.filterobject(flags, function(flag){     return flag   }) }) 

i need way have actionsflags object contains props equal true.

as of version 1.7 _.pick function can take iteratee can used instead of filterobject:

var requiredflags = _.mapobject(actionsflags, function(flags){     return _.pick(flags, function(flag){         return flag === true;     }) }) 

Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -