Skip to content

Instantly share code, notes, and snippets.

@danielrw7
Created July 10, 2015 22:39
Show Gist options
  • Save danielrw7/1f480715fe6613f1665f to your computer and use it in GitHub Desktop.
Save danielrw7/1f480715fe6613f1665f to your computer and use it in GitHub Desktop.
Object mapping and filtering
MapObj = (obj, mapFn) ->
if obj.length && obj.join
return obj.map(mapFn)
result = {}
result[key] = mapFn(val, key) for key, val of obj
result
FilterObj = (obj, filterFn) ->
if obj.length && obj.join
return obj.filter(filterFn)
result = {}
result[key] = val for key, val of obj when filterFn(val, key)
result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment