Created
March 23, 2015 23:19
-
-
Save leebyron/047ff870dcd2a5e2d5f2 to your computer and use it in GitHub Desktop.
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
var tree = Immutable.fromJS( | |
{id: 0, children: [{id: 1, children: [{id: 2}, {id: 3}]}, {id: 4, children: [{id: 5}, {id: 6}]}]} | |
); | |
function reduceFn(list, item) { | |
var children = item.get('children'); | |
list = children ? children.reduce(reduceFn, list) : list; | |
list = list.push(Immutable.Map({id: item.get('id')})); | |
return list; | |
} | |
var ids = Immutable.List.of(tree).reduce(reduceFn, Immutable.List()); | |
console.log(ids.toString()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment