Skip to content

Commit fd0cb50

Browse files
committedJan 4, 2019
--fix: returning node in getFirst() & getLast() instead of value
1 parent ed2eb43 commit fd0cb50

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed
 

‎src/_DataStructures_/LinkedList/LinkedList.test.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@ describe('Data Structures: Linked Lists', () => {
4343

4444
it('Should return the 10 as the first element in the list', () => {
4545
list.addAtBeginning(10);
46-
expect(list.getFirst(10));
46+
expect(list.getFirst().data).toEqual(10);
4747
});
4848
});
4949

5050
describe('addAtEnd(value)', () => {
5151
it('Should add element at end', () => {
5252
list.addAtBeginning(10);
5353
list.addAtEnd(12);
54-
expect(list.getLast()).toEqual(12);
54+
expect(list.getLast().data).toEqual(12);
5555
});
5656

5757
it('Should add at the beginning if the list is empty', () => {
@@ -151,7 +151,7 @@ describe('Data Structures: Linked Lists', () => {
151151
list.addAtEnd(23);
152152
list.addAtEnd(33);
153153
list.addAtEnd(10);
154-
expect(list.getLast()).toEqual(10);
154+
expect(list.getLast().data).toEqual(10);
155155
});
156156
});
157157

@@ -165,7 +165,7 @@ describe('Data Structures: Linked Lists', () => {
165165
list.addAtEnd(23);
166166
list.addAtEnd(33);
167167
list.addAtEnd(10);
168-
expect(list.getFirst()).toEqual(15);
168+
expect(list.getFirst().data).toEqual(15);
169169
});
170170
});
171171
});

‎src/_DataStructures_/LinkedList/index.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -57,21 +57,18 @@ class LinkedList {
5757
if (!this.head) {
5858
return null;
5959
}
60-
return this.head.data;
60+
return this.head;
6161
}
6262

6363
getLast() {
6464
if (!this.head) {
6565
return null;
6666
}
67-
6867
let address = this.head;
69-
7068
while (address.next) {
7169
address = address.next;
7270
}
73-
74-
return address.data;
71+
return address;
7572
}
7673

7774
length() {

0 commit comments

Comments
 (0)