Skip to content

Instantly share code, notes, and snippets.

@exebetche
Created August 9, 2015 23:06
Show Gist options
  • Save exebetche/fb6249e6fe118051bf94 to your computer and use it in GitHub Desktop.
Save exebetche/fb6249e6fe118051bf94 to your computer and use it in GitHub Desktop.
function parse_object(obj){
var stack =[[Object.keys(obj), obj]],
t = stack[0],
o,
k = t[0].shift();
while(true){
while(k){
if(typeof t[1][k]=="object"){
o = t[1][k];
t = [Object.keys(o), o];
stack.push(t);
// do something when going down
}
else{
// do somethin with value
}
k = t[0].shift();
}
while(!k){
stack.pop();
t = stack[stack.length-1];
if(!t) {
return;
}
k = t[0].shift();
// do something when going up
}
}
}
var test = {
"type": "FunctionDeclaration",
"id": {
"type": "Identifier",
"name": "test1"
},
"params": [],
"defaults": []
};
parse_object(test);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment