Last active
August 29, 2015 14:12
-
-
Save tarot/1e5cbe504a1712dadd54 to your computer and use it in GitHub Desktop.
map values for underscore.js
This file contains hidden or 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 | |
| map_values: (obj, iteratee, context) -> | |
| iteratee = @iteratee iteratee, context | |
| @object @map obj, (v, k, o) -> [k, iteratee(v, k, o)] |
This file contains hidden or 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({ | |
| map_values: function(obj, iteratee, context) { | |
| iteratee = this.iteratee(iteratee, context); | |
| return this.object(this.map(obj, function(v, k, o) { | |
| return [k, iteratee(v, k, o)]; | |
| })); | |
| } | |
| }); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
_.map_values({a: 1, b: 2}, function(e) { return e + e; })=> {a: 2, b: 4}