Last active
October 30, 2016 16:03
-
-
Save Fabiantjoeaon/2e03ad056e8b3c85e6d452432abb16f4 to your computer and use it in GitHub Desktop.
Object tree mapper, executes map for every node in tree. Src: @mpjme, https://www.youtube.com/watch?v=2jp8N6Ha7tY
This file contains hidden or 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
const mapTree = (node,mapper) => { | |
return { | |
value: mapper(node.value), | |
nodes: node.nodes | |
? node.nodes.map( x => | |
mapTree(x, mapper) | |
) | |
: null | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment