Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
var o = {
value: 1,
left: {
value: 2,
left: {
value: 4
},
right: {
value: 5
}
},
right: {
value: 3,
left: {
value: 6
},
right: {
value: 7
}
}
};
var fn = function (node) {
var arr = [];
var l = node.left;
var r = node.right;
l && arr.push(l.value);
r && arr.push(r.value);
if (l) {
arr = arr.concat(fn(l));
}
if (r) {
arr = arr.concat(fn(r));
}
if (arr.length === 6) {
arr.unshift(node.value);
}
return arr;
};
console.log(fn(o));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.