/**
 * Pre-order traversal explores the root nodes before the leaf nodes.
 *
 */
const traversePreOrder = (root) => {
  const result = []

  function traverseInOrderHelper(node) {
    if (!node) return

    result.push(node.val)

    traverseInOrderHelper(node.left)

    traverseInOrderHelper(node.right)
  }

  traverseInOrderHelper(root)

  return result
}

module.exports = traversePreOrder
