2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								---
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								id: 587d8251367417b2b2512c63
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								title: Remove Elements from a Linked List
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								challengeType: 1
							 
						 
					
						
							
								
									
										
										
										
											2019-08-05 09:17:33 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								forumTopicId: 301712
							 
						 
					
						
							
								
									
										
										
										
											2021-01-13 03:31:00 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								dashedName: remove-elements-from-a-linked-list
							 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								---
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-11-27 19:02:05 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# --description--
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								The next important method that any implementation of a linked list will need is a `remove`  method. This method should take the element we want to remove as an argument, and then search the list to find and remove the node that contains that element.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Whenever we remove a node from a linked list, it's important that we don't accidentally orphan the rest of the list in doing so. Recall that every node's `next`  property points to the node that follows it in the list. If we're removing the middle element, say, we'll want to make sure that we have a connection from that element's previous node's `next`  property to the middle element's `next`  property (which is the next node in the list!)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								This might sound really confusing, so let's return to the conga line example so we have a good conceptual model. Picture yourself in a conga line, and the person directly in front of you leaves the line. The person who just left the line no longer has her hands on anyone in line--and you no longer have your hands on the person that left. You step forward and put your hands on next person you see.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-11-27 19:02:05 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								If the element we wish to remove is the `head`  element, we reassign the `head`  to the second node of the linked list.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# --instructions--
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Write a `remove`  method that takes an element and removes it from the linked list.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								**Note:** The `length`  of the list should decrease by one every time an element is removed from the linked list.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# --hints--
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Your `LinkedList`  class should have a `remove`  method.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```js
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								assert(
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  (function () {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    var test = new LinkedList();
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return typeof test.remove === 'function';
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  })()
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								);
							 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-11-27 19:02:05 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Your `remove`  method should reassign `head`  to the second node when the first node is removed.
							 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-11-27 19:02:05 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								```js
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								assert(
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  (function () {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    var test = new LinkedList();
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    test.add('cat');
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    test.add('dog');
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    test.remove('cat');
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return test.head().element === 'dog';
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  })()
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Your `remove`  method should decrease the `length`  of the linked list by one for every node removed.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```js
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								assert(
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  (function () {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    var test = new LinkedList();
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    test.add('cat');
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    test.add('dog');
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    test.add('hamster');
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    test.remove('cat');
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    test.remove('fish');
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return test.size() === 2;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  })()
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Your `remove`  method should reassign the reference of the previous node of the removed node to the removed node's `next`  reference.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```js
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								assert(
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  (function () {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    var test = new LinkedList();
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    test.add('cat');
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    test.add('dog');
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    test.add('snake');
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    test.add('kitten');
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    test.remove('snake');
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return test.head().next.next.element === 'kitten';
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  })()
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Your `remove`  method should not change the linked list if the element does not exist in the linked list.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```js
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								assert(
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  (function () {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    var test = new LinkedList();
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    test.add('cat');
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    test.add('dog');
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    test.add('kitten');
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    test.remove('elephant');
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return (
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      JSON.stringify(test.head()) ===
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      '{"element":"cat","next":{"element":"dog","next":{"element":"kitten","next":null}}}'
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    );
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  })()
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# --seed--
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								## --seed-contents--
  
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```js
							 
						 
					
						
							
								
									
										
										
										
											2018-10-08 01:01:53 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								function LinkedList() {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  var length = 0;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  var head = null;
							 
						 
					
						
							
								
									
										
										
										
											2019-03-25 09:53:38 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-10-08 01:01:53 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  var Node = function(element){
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    this.element = element;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    this.next = null;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  };
							 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  this.size = function(){
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return length;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  };
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  this.head = function(){
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return head;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  };
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  this.add = function(element){
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    var node = new Node(element);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if(head === null){
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        head = node;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } else {
							 
						 
					
						
							
								
									
										
										
										
											2020-07-08 17:58:15 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								      var currentNode = head;
							 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-07-08 17:58:15 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								      while(currentNode.next){
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        currentNode  = currentNode.next;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      }
							 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-07-08 17:58:15 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								      currentNode.next = node;
							 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    length++;
							 
						 
					
						
							
								
									
										
										
										
											2018-10-08 01:01:53 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  };
							 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  this.remove = function(element){
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // Only change code below this line
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // Only change code above this line
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  };
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-11-27 19:02:05 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# --solutions--
  
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```js
							 
						 
					
						
							
								
									
										
										
										
											2019-06-04 11:55:50 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								function LinkedList() {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  var length = 0;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  var head = null;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  var Node = function(element){
							 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    this.element = element;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    this.next = null;
							 
						 
					
						
							
								
									
										
										
										
											2019-06-04 11:55:50 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  };
							 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-06-04 11:55:50 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  this.size = function(){
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return length;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  };
							 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-06-04 11:55:50 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  this.head = function(){
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return head;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  };
							 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-06-04 11:55:50 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  this.add = function(element){
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    var node = new Node(element);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if(head === null){
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        head = node;
							 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    } else {
							 
						 
					
						
							
								
									
										
										
										
											2019-06-04 11:55:50 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        var currentNode = head;
							 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-06-04 11:55:50 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        while(currentNode.next){
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            currentNode  = currentNode.next;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        }
							 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-06-04 11:55:50 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        currentNode.next = node;
							 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
									
										
										
										
											2018-10-08 01:01:53 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-06-04 11:55:50 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    length++;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  };
							 
						 
					
						
							
								
									
										
										
										
											2018-10-08 01:01:53 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-06-04 11:55:50 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  this.remove = function(element){
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if (head === null) {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      return;
							 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
									
										
										
										
											2019-06-04 11:55:50 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    var previous;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    var currentNode = head;
							 
						 
					
						
							
								
									
										
										
										
											2018-10-08 01:01:53 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-06-04 11:55:50 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    while (currentNode.next !== null & &  currentNode.element !== element) {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      previous = currentNode;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      currentNode = currentNode.next;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if (currentNode.next === null & &  currentNode.element !== element) {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      return;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    else if (previous) {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      previous.next = currentNode.next;
							 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    } else {
							 
						 
					
						
							
								
									
										
										
										
											2019-06-04 11:55:50 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								      head = currentNode.next;
							 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
									
										
										
										
											2018-10-08 01:01:53 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-06-04 11:55:50 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    length--;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  };
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} 
							 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								```