diff --git a/Chapter6/chap6-4.txt b/Chapter6/chap6-4.txt index 4a78c04..95eb57f 100644 --- a/Chapter6/chap6-4.txt +++ b/Chapter6/chap6-4.txt @@ -35,7 +35,10 @@ function remove(item) { var currNode = this.find(item); if (!(currNode.next == null)) { currNode.previous.next = currNode.next; - currNode.next.previous = currNode.previous; + // if we try to remove last element in the list via this method it will fail as previous of null. + if (current.next !== null) { + currNode.next.previous = currNode.previous; + } currNode.next = null; currNode.previous = null; } @@ -72,6 +75,10 @@ function insert(newElement, item) { var current = this.find(item); newNode.next = current.next; newNode.previous = current; + // if there is next element than it should have previous reference to current one or else it would preserve reference to it's previous element in th list + if (newNode.next) { + newNode.next.previous = newNode; + } current.next = newNode; } pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy