block by joyrexus 9833272

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