code: function insertNode (i, last) {
    var node = new Node(i)
  
    if (!last) {
      node.prev = node
      node.next = node
  
    } else {
      node.next = last.next
      node.prev = last
      last.next.prev = node
      last.next = node
    }
    return node
  }
docs: create a node and optionally link it with previous one (in a circular doubly linked list)