walker? idk

This commit is contained in:
Seth Trowbridge 2025-03-06 13:53:00 -05:00
parent 869b406323
commit 342ca8c5fc

View File

@ -1,6 +1,8 @@
function Walk(obj)
{
const set = new Set(); const set = new Set();
function Walk(obj, parentObject, propertyName, path=[]) function Step(obj, path="")
{ {
if(obj !== null && typeof obj === "object") if(obj !== null && typeof obj === "object")
{ {
@ -17,18 +19,21 @@ function Walk(obj, parentObject, propertyName, path=[])
for(let key in obj) for(let key in obj)
{ {
const val = obj[key]; const val = obj[key];
console.log(key, val); console.log(" >stepping into", path+"."+key);
Walk(val, obj, key); Step(val, path+"."+key);
} }
console.log("-----------------"); console.log("-----------------");
} }
} }
else else
{ {
console.log(obj, "is a leaf") console.log(obj, "is a leaf");
} }
} }
Step(obj);
}
const root = {hey:"1", deep:{}, arr:["a", "b"]};
const root = {hey:"1", deep:{basement:{closet:{item1:"one", item2:"two"}}}, arr:["a", "b"]};
root.circ = root; root.circ = root;
Walk(root); Walk(root);