function sortedInsert(head, data) {
  let newNode = new DoublyLinkedListNode(data);

  if (head == null) {
    return newNode;
  }
  else if (data <= head.data) {
    newNode.next = head;
    head.prev = newNode;
    head = newNode;
    return newNode;
  }
  else {
    let rest = sortedInsert(head.next, data);
    head.next = rest;
    rest.prev = head;
    return head;
  }

}
/*Pseudocode:
1. Declare a variable called newNode and set it equal to a new instantiation of a DoublyLinkedListNode, passing in input data as its value
2. Make a base case of if head is equal to null (head does not exist) then just return newNode.
3. Make another base case of if data is less than or equal to head.data then set newNode.next equal to head, then set head.prev to newNode and
finally set head equal to newNode to re-set the head to be the newNode and then return newNode.
4. Else (if data is more than head.data) then declare a variable called rest and set it equal to the recursive call of the sortedInsert 
function, this time passing in head.next to be the head input and data to be the data input. (This will insert the newNode at head.next if 
  there's only a head in the linked list, it'll insert newNode at the head.next place if newNode belongs as 2nd node in list or it'll keep 
  iterating through list till it finds a node that's bigger than newNode)
5. Next, (once recursive call of function is done and saved to a variable called rest) still inside else statement, set head.next equal to 
rest, then set rest.prev equal to head and finally return head inside the else statement.
 */
1. Declare a variable called newNode and set it equal to a new instantiation of a DoublyLinkedListNode, passing in input data as its value
2. Make a base case of if head is equal to null (head does not exist) then just return newNode.
3. Make another base case of if data is less than or equal to head.data then set newNode.next equal to head, then set head.prev to newNode and
finally set head equal to newNode to re-set the head to be the newNode and then return newNode.
4. Else (if data is more than head.data) then declare a variable called rest and set it equal to the recursive call of the sortedInsert
function, this time passing in head.next to be the head input and data to be the data input. (This will insert the newNode at head.next if
there's only a head in the linked list, it'll insert newNode at the head.next place if newNode belongs as 2nd node in list or it'll keep
iterating through list till it finds a node that's bigger than newNode)
5. Next, (once recursive call of function is done and saved to a variable called rest) still inside else statement, set head.next equal to
rest, then set rest.prev equal to head and finally return head inside the else statement.
1 . Declare a variable called newNode and set it equal to a new instantiation of a DoublyLinkedListNode passing in input data as its value 2 . Make a base case of if head is equal to null ( head does not exist ) then just return newNode . 3 . Make another base case of if data is less than or equal to head . data then set newNode . next equal to head then set head . prev to newNode and finally set head equal to newNode to re - set the head to be the newNode and then return newNode . 4 . Else ( if data is more than head . data ) then declare a variable called rest and set it equal to the recursive call of the sortedInsert function this time passing in head . next to be the head input and data to be the data input . ( This will insert the newNode at head . next if there ' s only a head in the linked list it ' ll insert newNode at the head . next place if newNode belongs as 2nd node in list or it ' ll keep iterating through list till it finds a node that ' s bigger than newNode ) 5 . Next ( once recursive call of function is done and saved to a variable called rest ) still inside else statement set head . next equal to rest then set rest . prev equal to head and finally return head inside the else statement .
function sortedInsert(head, data) {
  let newNode = new DoublyLinkedListNode(data);
  if (head == null) {
    return newNode;
  }
  else if (data <= head.data) {
    newNode.next = head;
    head.prev = newNode;
    head = newNode;
    return newNode;
  }
  else {
    let rest = sortedInsert(head.next, data);
    head.next = rest;
    rest.prev = head;
    return head;
  }
}
function sortedInsert ( head , data ) { let newNode = new DoublyLinkedListNode ( data ) ; if ( head == null ) { return newNode ; } else if ( data <= head . data ) { newNode . next = head ; head . prev = newNode ; head = newNode ; return newNode ; } else { let rest = sortedInsert ( head . next , data ) ; head . next = rest ; rest . prev = head ; return head ; } }
Pseudocode:
1.
Pseudocode : 1 .