N-ary Tree Level Order Traversal LeetCode solution in JavaScript
1var levelOrder = function (root) {2if (!root) return [];34const Q = [[root, 0]];5const op = [];67while (Q.length) {8const [node, level] = Q.shift();910if (op.length <= level) {11op[level] = [];12}13op[level].push(node.val);1415for (const child of node.children) {16Q.push([child, level + 1]);17}18}19return op;20};