Created
July 10, 2015 22:39
-
-
Save postpostscript/1f480715fe6613f1665f to your computer and use it in GitHub Desktop.
Object mapping and filtering
This file contains 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
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