Created
August 9, 2015 23:06
-
-
Save exebetche/fb6249e6fe118051bf94 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
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