function flatten(head) {
  for (let curr = head; curr; curr = curr.next) {
    if (!curr.child) continue;

    let last = curr.child;
    while (last && last.next) last = last.next; // find "child"'s last
    if (curr.next) { // move "next" to "child"'s last postion
      last.next = curr.next;
      curr.next.previous = last;
    }
    curr.next = curr.child; // override "next" with "child".
    curr.child.previous = curr;
    curr.child = null; // clean "child" pointer.
  }

  return head;
}
Flatten a multi-level to a single level
@param {Node} head
@return {Node}