Skip to content

Commit

Permalink
check for undefined as well as null
Browse files Browse the repository at this point in the history
  • Loading branch information
jhchen committed Oct 8, 2012
1 parent c41f79e commit b418793
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions lib/linked_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,20 @@ LinkedList.prototype = {
LinkedList.prototype.append = function(node) {
if (typeof this.first === 'undefined' || this.first === null) {
this.first = node;
this.last = node;
} else {
node.prev = this.last;
node.next = null;
this.last.next = node;
this.last = node;
}
node.prev = this.last;
this.last = node;
this.length++;
};

LinkedList.prototype.insertAfter = function(node, newNode) {
newNode.prev = node;
if (node) {
newNode.next = node.next;
if (typeof node.next !== 'undefined' && node.next !== null) {
if (typeof node.next != 'undefined' && node.next !== null) {
node.next.prev = newNode;
}
node.next = newNode;
Expand Down

0 comments on commit b418793

Please sign in to comment.