File tree 2 files changed +6
-9
lines changed
src/_DataStructures_/LinkedList
2 files changed +6
-9
lines changed Original file line number Diff line number Diff line change @@ -43,15 +43,15 @@ describe('Data Structures: Linked Lists', () => {
43
43
44
44
it ( 'Should return the 10 as the first element in the list' , ( ) => {
45
45
list . addAtBeginning ( 10 ) ;
46
- expect ( list . getFirst ( 10 ) ) ;
46
+ expect ( list . getFirst ( ) . data ) . toEqual ( 10 ) ;
47
47
} ) ;
48
48
} ) ;
49
49
50
50
describe ( 'addAtEnd(value)' , ( ) => {
51
51
it ( 'Should add element at end' , ( ) => {
52
52
list . addAtBeginning ( 10 ) ;
53
53
list . addAtEnd ( 12 ) ;
54
- expect ( list . getLast ( ) ) . toEqual ( 12 ) ;
54
+ expect ( list . getLast ( ) . data ) . toEqual ( 12 ) ;
55
55
} ) ;
56
56
57
57
it ( 'Should add at the beginning if the list is empty' , ( ) => {
@@ -151,7 +151,7 @@ describe('Data Structures: Linked Lists', () => {
151
151
list . addAtEnd ( 23 ) ;
152
152
list . addAtEnd ( 33 ) ;
153
153
list . addAtEnd ( 10 ) ;
154
- expect ( list . getLast ( ) ) . toEqual ( 10 ) ;
154
+ expect ( list . getLast ( ) . data ) . toEqual ( 10 ) ;
155
155
} ) ;
156
156
} ) ;
157
157
@@ -165,7 +165,7 @@ describe('Data Structures: Linked Lists', () => {
165
165
list . addAtEnd ( 23 ) ;
166
166
list . addAtEnd ( 33 ) ;
167
167
list . addAtEnd ( 10 ) ;
168
- expect ( list . getFirst ( ) ) . toEqual ( 15 ) ;
168
+ expect ( list . getFirst ( ) . data ) . toEqual ( 15 ) ;
169
169
} ) ;
170
170
} ) ;
171
171
} ) ;
Original file line number Diff line number Diff line change @@ -57,21 +57,18 @@ class LinkedList {
57
57
if ( ! this . head ) {
58
58
return null ;
59
59
}
60
- return this . head . data ;
60
+ return this . head ;
61
61
}
62
62
63
63
getLast ( ) {
64
64
if ( ! this . head ) {
65
65
return null ;
66
66
}
67
-
68
67
let address = this . head ;
69
-
70
68
while ( address . next ) {
71
69
address = address . next ;
72
70
}
73
-
74
- return address . data ;
71
+ return address ;
75
72
}
76
73
77
74
length ( ) {
You can’t perform that action at this time.
0 commit comments