Skip to content

Instantly share code, notes, and snippets.

@Fabiantjoeaon
Last active October 30, 2016 16:03
Show Gist options
  • Save Fabiantjoeaon/2e03ad056e8b3c85e6d452432abb16f4 to your computer and use it in GitHub Desktop.
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
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