function inorder(root, array = []) {
if (root) {
inorder(root.left, array);
array.push(root.val);
inorder(root.right, array);
}
return array;
};
const inOrder = function (root) {
const result = [];
const stack = [];
let current = root;
while (current || stack.length > 0) {
while (current) {
stack.push(current);
current = current.left;
}
current = stack.pop();
result.push(current.val);
current = current.right;
}
return result;
};