Skip to content

Instantly share code, notes, and snippets.

@sorribas
Created June 22, 2014 15:39
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 sorribas/6964d0d5a4df66cf046b to your computer and use it in GitHub Desktop.
Save sorribas/6964d0d5a4df66cf046b to your computer and use it in GitHub Desktop.
var transverser = function(obj) {
var result = [];
var pusher = function(str, arr) {
arr.forEach(function(obj) {
if (obj.perms) return pusher(str + obj.value, obj.perms);
result.push(str + obj.value);
});
};
pusher('', obj)
return result;
};
var res = transverser([{"value":1,"perms":[{"value":1},{"value":2},{"value":4}]},{"value":2,"perms":[{"value":1},{"value":2},{"value":4}]},{"value":4,"perms":[{"value":1},{"value":2},{"value":4}]}]);
console.log(res);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment