text: function TreeNode(val, left, right) {
    this.val = val === undefined ? 0 : val
    this.left = left === undefined ? null : left
    this.right = right === undefined ? null : right
  }
  
  /**
   * @param {TreeNode} root
   */
  var BSTIterator = function (root) {
    this.root = root
    this.arr = []
    this.getValsArray()
  }
  
  BSTIterator.prototype.proccesRoot = function (currentRoot) {
    if (!currentRoot) return null
    this.arr.push(currentRoot.val)
    if (currentRoot.left) this.proccesRoot(currentRoot.left)
    if (currentRoot.right) this.proccesRoot(currentRoot.right)
  }
  
  BSTIterator.prototype.getValsArray = function () {
    this.proccesRoot(this.root)
    this.arr = this.arr.sort((a, b) => a - b)
  }
  
  /**
   * @return the next smallest number
   * @return {number}
   */
  BSTIterator.prototype.next = function () {
    return this.hasNext() ? this.arr.shift() : undefined
  }
  
  /**
   * @return whether we have a next smallest number
   * @return {boolean}
   */
  BSTIterator.prototype.hasNext = function () {
    return !!this.arr.length
  }
  
  const root = new TreeNode(
    7,
    new TreeNode(3, null, null),
    new TreeNode(15, new TreeNode(9, null, null), new TreeNode(20, null, null))
  )
  
  const iterator = new BSTIterator(root)
  console.log(iterator.arr)
  iterator.next() // return 3
  iterator.next() // return 7
  iterator.hasNext() // return true
  iterator.next() // return 9
  iterator.hasNext() // return true
  iterator.next() // return 15
  iterator.hasNext() // return true
  iterator.next() // return 20
  iterator.hasNext() // return false
  