function BinaryTree() { let Node = function (val) { this.val = val this.left = null this.right = null } this.root = null } var preorderTraversal = (root) => { let result = [] var preorderTraverseNode = (node) => { if (node) { result.push(node.val) preorderTraverseNode(node.left) preorderTraverseNode(node.right) } } preorderTraverseNode(root) return result }