Fix LinkedList (#42)

This commit is contained in:
m-maksyutin 2018-06-02 09:23:55 +03:00 committed by Oleksii Trekhleb
parent 87299a5153
commit a63bc67cf4
2 changed files with 4 additions and 3 deletions

View File

@ -60,7 +60,7 @@ export default class LinkedList {
let deletedNode = null;
// If the head must be deleted then make 2nd node to be a head.
if (this.compare.equal(this.head.value, value)) {
while (this.head && this.compare.equal(this.head.value, value)) {
deletedNode = this.head;
this.head = this.head.next;
}

View File

@ -32,6 +32,7 @@ describe('LinkedList', () => {
expect(linkedList.delete(5)).toBeNull();
linkedList.append(1);
linkedList.append(1);
linkedList.append(2);
linkedList.append(3);
@ -45,10 +46,10 @@ describe('LinkedList', () => {
const deletedNode = linkedList.delete(3);
expect(deletedNode.value).toBe(3);
expect(linkedList.toString()).toBe('1,2,4,5');
expect(linkedList.toString()).toBe('1,1,2,4,5');
linkedList.delete(3);
expect(linkedList.toString()).toBe('1,2,4,5');
expect(linkedList.toString()).toBe('1,1,2,4,5');
linkedList.delete(1);
expect(linkedList.toString()).toBe('2,4,5');