diff --git a/src/LinkedHashMap.js b/src/LinkedHashMap.js index 677897a..7e5a2c6 100644 --- a/src/LinkedHashMap.js +++ b/src/LinkedHashMap.js @@ -94,7 +94,9 @@ var key = node.getKey(); if (node === this.private.first) { this.private.first = this.private.first.getNext(); - this.private.first.setPrevious(null); + if (this.private.first instanceof Node) { + this.private.first.setPrevious(null); + } } else if (node === this.private.last) { this.private.last = this.private.last.getPrevious(); this.private.last.setNext(null); @@ -102,6 +104,7 @@ node.getPrevious().setNext(node.getNext()); node.getNext().setPrevious(node.getPrevious()); } + this.private.count--; delete this.private.hashMap[key]; } }; diff --git a/test/spec/LinkedHashMapSpec.js b/test/spec/LinkedHashMapSpec.js index 271b93e..8174205 100644 --- a/test/spec/LinkedHashMapSpec.js +++ b/test/spec/LinkedHashMapSpec.js @@ -114,6 +114,13 @@ expect(first.getPrevious()).toEqual(null); }); + it('should be able to delete all entries', function removeFirstWithRemove() { + list.remove(0); + list.remove(1); + list.remove(2); + expect(list.isEmpty()).toEqual(true); + }); + it('should be able to remove the last entry', function removeLast() { list.removeLast(); var last = list.getLast();