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

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

    traverseInOrderHelper(node.left)

    traverseInOrderHelper(node.right)

    result.push(node.val)
  }

  traverseInOrderHelper(root)

  return result
}

module.exports = traversePostOrder
