Javascript 90% faster, 100% less memory. Recursive.
The idea is the following: \n If a node has a child:\n1. Keep a reference of node.next as nextNode;\n1. Find the tail of node\'s child (implement a findTail fun
The idea is the following: \n* If a node has a child:\n1. Keep a reference of node.next as nextNode;\n1. Find the tail of node\'s child (implement a findTail function)\n1. The tail of node\'s child will have nextNode as its next.\n1. Change node.next to the child and set node.child = null;\n* Recursively do this over the child (which at this point should be node.next)\n* Keep a reference to the original head and return it.\n\n    \n```JS\nvar flatten = function(head) {\n    \n    if(head===null){\n        return null;\n    }\n    \n    let current = head;\n    \n    if(current.child){\n        let tail = findTail(current.child);\n        let nextNode = current.next;\n        current.next = current.child;\n        current.child.prev = current;\n        if(nextNode) nextNode.prev = tail;\n        tail.next = nextNode;\n        current.child = null;\n    }\n    \n    flatten(current.next)\n    \n    return head;\n};\n\n\nfunction findTail(node){\n        \n    while(node.next){\n        node = node.next;\n    }\n    return node;        \n\t\n}\n```
['Linked List', 'Recursion', 'JavaScript']