Problem in remove function in Doubly Linked List

My code is not passing the last test case. It shows following error:

The last item can be removed from the list.

My code is:


var Node = function(data, prev) {
  this.data = data;
  this.prev = prev;
  this.next = null;
};
var DoublyLinkedList = function() {
  this.head = null;
  this.tail = null;
  // change code below this line
  this.add = function(data){
    let newNode = new Node(data, null);
    if(this.head == null){
      this.head = newNode;
      this.tail = newNode;
      return 1;
    }
    this.tail.next = newNode;
    newNode.prev = this.tail;
    this.tail = newNode;
    return 1;
  }

  this.remove = function(data){
    if(this.head != null){
      if(this.head.data == data){
        this.head = this.head.next;
        this.head.prev = null;
      }
      let currNode = this.head.next;
      while(currNode.next != null){
        if(currNode.data = data){
          let prevNode = currNode.prev;
          let nextNode = currNode.next;
          prevNode.next = nextNode;
          nextNode.prev = prevNode;
        }
        currNode = currNode.next;
      }
      if(currNode.data == data && currNode.next == null){
        let prevNode = currNode.prev;
        prevNode.next = null;
        this.tail = prevNode;
      }
      return 1;
    }
    return null;
  }
  // change code above this line
};

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:60.0) Gecko/20100101 Firefox/60.0.

Link to the challenge:
https://learn.freecodecamp.org/coding-interview-prep/data-structures/create-a-doubly-linked-list/

Funny enough, I just did this challenge last night… and you’re gonna hate what yours is missing :wink:

Inside your while loop, verify your if statement is using the correct operator on your comparison.

Almost an hour of frustration and then you get this :face_with_hand_over_mouth:

1 Like

Right?! I have a love/hate relationship when the solution turns out to be something almost equivalent to a typo of sorts.