-
-
Save gpittau/4288106 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_.mixin({ | |
// ### _.objMap | |
// _.map for objects, keeps key/value associations | |
objMap: function (input, mapper, context) { | |
return _.reduce(input, function (obj, v, k) { | |
obj[k] = mapper.call(context, v, k, input); | |
return obj; | |
}, {}, context); | |
}, | |
// ### _.objFilter | |
// _.filter for objects, keeps key/value associations | |
// but only includes the properties that pass test(). | |
objFilter: function (input, test, context) { | |
return _.reduce(input, function (obj, v, k) { | |
if (test.call(context, v, k, input)) { | |
obj[k] = v; | |
} | |
return obj; | |
}, {}, context); | |
}, | |
// ### _.objReject | |
// | |
// _.reject for objects, keeps key/value associations | |
// but does not include the properties that pass test(). | |
objReject: function (input, test, context) { | |
return _.reduce(input, function (obj, v, k) { | |
if (!test.call(context, v, k, input)) { | |
obj[k] = v; | |
} | |
return obj; | |
}, {}, context); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment