Skip to content

Instantly share code, notes, and snippets.

@tarot
Last active August 29, 2015 14:12
Show Gist options
  • Select an option

  • Save tarot/1e5cbe504a1712dadd54 to your computer and use it in GitHub Desktop.

Select an option

Save tarot/1e5cbe504a1712dadd54 to your computer and use it in GitHub Desktop.
map values for underscore.js
_.mixin
map_values: (obj, iteratee, context) ->
iteratee = @iteratee iteratee, context
@object @map obj, (v, k, o) -> [k, iteratee(v, k, o)]
_.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)];
}));
}
});
@tarot

tarot commented Dec 27, 2014

Copy link
Copy Markdown
Author

_.map_values({a: 1, b: 2}, function(e) { return e + e; })

=> {a: 2, b: 4}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment