const traverseLevelOrder = (root) => {
  let result = []
  let queue = []

  // we have nothing to traverse
  if (!root) return

  queue.push(root)

  while (queue.length) {
    var temp = queue.shift()
    result.push(temp.val)

    if (temp.left) queue.push(temp.left)
    if (temp.right) queue.push(temp.right)
  }

  return result
}

module.exports = traverseLevelOrder
