Skip to content

Instantly share code, notes, and snippets.

@leebyron
Created March 23, 2015 23:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leebyron/047ff870dcd2a5e2d5f2 to your computer and use it in GitHub Desktop.
Save leebyron/047ff870dcd2a5e2d5f2 to your computer and use it in GitHub Desktop.
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