Junior — Senior
Recursive traversal of a binary tree with sum of values calculation
livecode
Task condition
Given an object describing a binary tree. You need to implement a function that recursively traverses all nodes of the tree and returns the total sum of the value fields.
const binaryTree = {
value: 6,
left: {
value: 5,
left: {
value: 3,
left: {
value: 1
}
},
right: {
value: 7
}
},
right: {
value: 10,
left: {
value: 4
},
right: {
value: 5
}
}
}