Skip to content

Instantly share code, notes, and snippets.

@joyrexus
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joyrexus/9833272 to your computer and use it in GitHub Desktop.
Save joyrexus/9833272 to your computer and use it in GitHub Desktop.
Map a function over the values of an object

mapValues

Maps a function over the values of an object.

mapValues = (obj, f) ->
  result = {}
  result[k] = f(v) for k, v of obj
  result

Usage

{ok, deepEqual} = require 'assert'
eq = deepEqual

data = 
  one: 1
  two: 2
  three: 3

eq mapValues(data, (v) -> v * v), 
  one: 1
  two: 4
  three: 9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment