walker started
This commit is contained in:
parent
06ee58439a
commit
cec0803aff
34
walker.js
Normal file
34
walker.js
Normal file
@ -0,0 +1,34 @@
|
||||
|
||||
const set = new Set();
|
||||
function Walk(obj, parentObject, propertyName, path=[])
|
||||
{
|
||||
if(obj !== null && typeof obj === "object")
|
||||
{
|
||||
if(set.has(obj))
|
||||
{
|
||||
console.log("ive been to", obj, "quitting");
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
set.add(obj);
|
||||
console.log("ive never seen", obj, "here are its fields:");
|
||||
console.log("-----------------");
|
||||
for(let key in obj)
|
||||
{
|
||||
const val = obj[key];
|
||||
console.log(key, val);
|
||||
Walk(val, obj, key);
|
||||
}
|
||||
console.log("-----------------");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
console.log(obj, "is a leaf")
|
||||
}
|
||||
}
|
||||
|
||||
const root = {hey:"1", deep:{}, arr:["a", "b"]};
|
||||
root.circ = root;
|
||||
Walk(root);
|
Loading…
Reference in New Issue
Block a user