JSFiddle - React, Tailwind, and code Playground
more codility on June 9 2017
by Matthew Day
JavaScript
var tree = {
5: {
left: {
value: 3,
left: {
value: 20,
left: {
value: 6,
right: null,
left: null
},
right: null
},
right: null
},
right: {
value: 10,
left: {
value: 1,
left: null,
right: null
},
right: {
value: 15,
left: {
value: 30,
left: null,
right: {
value: 9,
left: null,
right: null
}
},
right: {
value: 8,
left: null,
right: null
}
}
}
}
}
function solution(T) {
for(var key in T) {
console.log(key);
}
}
function iterate(obj) {
for (var property in obj) {
if (obj.hasOwnProperty(property)) {
if (typeof obj[property] == "object") {
console.log(property);
iterate(obj[property]);
} else {
console.log(property + " " + obj[property]);
}
}
}
}
//solution(tree);
iterate(tree);
// source
// https://stackoverflow.com/questions/5432967/how-to-iterate-over-inner-objects-property-in-an-object