Binary Tree Level Order Traversal

#LeetCode

whck6

let toArray = (root, arr, level, idx) => {
  if (!root) {
    return null;
  } else {
    if (!arr[level]) {
      arr[level] = [];
    }

    arr[level].push(root.val);
  }

  toArray(root.left, arr, level + 1, idx * 2);
  toArray(root.right, arr, level + 1, idx * 2 + 1);
};