💡JavaScript Solution
The idea\n1. Use a stack to keep track of different levels of child nodes\n2. For each node, link back to the prev node. This way it\'s easier to link the end o
### The idea\n1. Use a stack to keep track of different levels of child nodes\n2. For each node, link back to the `prev` node. This way it\'s easier to link the end of a child list to the parent list.\n``` javascript\nvar flatten = function(head) {\n    if (!head) return null;\n    let dummyHead = new Node(0, null, head, null);\n\n    let stack = [head];\n    let current = dummyHead;\n    let prev = null;\n\n    while(stack.length!=0) {        \n        current = stack.pop();\n        \n        if (prev) {\n            current.prev = prev;\n            prev.next = current;\n        } \n\n        if (current.next!=null) stack.push(current.next);\n        if (current.child!=null) { // has a child\n            stack.push(current.child);\n            current.child = null; // remove child reference\n        }\n        \n        prev = current;   \n    }\n    \n    return dummyHead.next;\n};\n```
['JavaScript']