// Source : https://leetcode.com/problems/binary-tree-inorder-traversal
// Author : Dean Shi
// Date   : 2017-02-27

/***************************************************************************************
 *
 * Given a binary tree, return the inorder traversal of its nodes' values.
 *
 * For example:
 * Given binary tree [1,null,2,3],
 *
 *    1
 *     \
 *      2
 *     /
 *    3
 *
 * return [1,3,2].
 *
 * Note: Recursive solution is trivial, could you do it iteratively?
 *
 *
 ***************************************************************************************/

/**
 * Definition for a binary tree node.
 * function TreeNode(val) {
 *     this.val = val;
 *     this.left = this.right = null;
 * }
 */
/**
 * @param {TreeNode} root
 * @return {number[]}
 */
var inorderTraversal = function(root) {
    const stack = []
    const result = []
    while (stack.length || root) {
        if (root) {
            stack.push(root)
            root = root.left
        } else {
            root = stack.pop()
            result.push(root.val)
            root = root.right
        }
    }
    return result
};

@@ -863,24 +863,8 @@
 le (
-stack.length %7C%7C 
 root
@@ -879,32 +879,55 @@
     if (root
-) %7B%0A    
+.right) stack.push(root.right)%0A
         stac
@@ -937,28 +937,30 @@
 ush(root
+.val
 )%0A
-  
         
   root =
@@ -947,33 +947,50 @@
 al)%0A        
-  root = 
+if (root.left) stack.push(
 root.left%0A  
@@ -986,16 +986,17 @@
 oot.left
+)
 %0A       
@@ -1000,26 +1000,17 @@
     
-%7D else %7B%0A 
+%0A
         
    r
@@ -1001,27 +1001,24 @@
    %0A        
-   
 root = stack
@@ -1024,16 +1024,79 @@
 k.pop()%0A
+        while (root !== void(0) && typeof root !== 'object') %7B%0A
         
@@ -1107,36 +1107,32 @@
 result.push(root
-.val
 )%0A            ro
@@ -1136,26 +1136,27 @@
  root = 
-root.right
+stack.pop()
 %0A       

Update BinaryTreeInorderTraversal.js