Skip to content

Commit 20d5b5c

Browse files
committed
--fix: returning nodes instead of node value
1 parent 098a7d6 commit 20d5b5c

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

src/_DataStructures_/LinkedList/LinkedList.test.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,14 @@ describe('Data Structures: Linked Lists', () => {
9898
describe('removeFromBeginning()', () => {
9999
it('Should remove element at front', () => {
100100
list.addAtBeginning(12);
101-
expect(list.removeFromBeginning()).toEqual(12);
101+
expect(list.removeFromBeginning().data).toEqual(12);
102102
expect(list.length()).toEqual(0);
103103
});
104104

105105
it('Should return the element after removing it', () => {
106106
list.addAtBeginning(15);
107107
list.addAtBeginning(16);
108-
expect(list.removeFromBeginning()).toEqual(16);
108+
expect(list.removeFromBeginning().data).toEqual(16);
109109
});
110110

111111
it('Should not throw error if the list is empty', () => {
@@ -122,7 +122,7 @@ describe('Data Structures: Linked Lists', () => {
122122
list.addAtBeginning('Hello');
123123
list.addAtBeginning(14);
124124
list.addAtEnd(15);
125-
expect(list.removeFromEnd()).toEqual(15);
125+
expect(list.removeFromEnd().data).toEqual(15);
126126
});
127127

128128
it('Should reduce the lengh of the list', () => {
@@ -137,7 +137,7 @@ describe('Data Structures: Linked Lists', () => {
137137
it('Should return the last element after removing it', () => {
138138
list.addAtBeginning(14);
139139
list.addAtEnd(15);
140-
expect(list.removeFromEnd()).toEqual(15);
140+
expect(list.removeFromEnd().data).toEqual(15);
141141
});
142142
});
143143

@@ -218,13 +218,13 @@ describe('Data Structures: Linked Lists', () => {
218218
expect(list.removeAt(10)).toEqual(null);
219219
});
220220

221-
it('Should remove last element for large index value', () => {
222-
expect(list.removeAt(10)).toEqual('Welcome');
221+
it('Should remove and return last element for large index value', () => {
222+
expect(list.removeAt(10).data).toEqual('Welcome');
223223
});
224224

225-
it('Should remove the element at given index value', () => {
226-
expect(list.removeAt(3)).toEqual('Welcome');
227-
expect(list.removeAt(2)).toEqual('There!');
225+
it('Should remove and return the element at given index value', () => {
226+
expect(list.removeAt(3).data).toEqual('Welcome');
227+
expect(list.removeAt(2).data).toEqual('There!');
228228
});
229229
});
230230
});

src/_DataStructures_/LinkedList/index.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ class LinkedList {
3232
if (!this.head) {
3333
return null;
3434
}
35-
const temp = this.head;
35+
const node = this.head;
3636
this.head = this.head.next;
37-
return temp.data;
37+
return node;
3838
}
3939

4040
removeFromEnd() {
@@ -46,9 +46,10 @@ class LinkedList {
4646
while (address.next.next) {
4747
address = address.next;
4848
}
49-
const { data } = address.next;
49+
50+
const node = address.next;
5051
address.next = null;
51-
return data;
52+
return node;
5253
}
5354

5455
getFirst() {
@@ -126,9 +127,9 @@ class LinkedList {
126127
count -= 1;
127128
}
128129

129-
const { data } = address.data;
130+
const node = address;
130131
previous.next = address.next.next;
131-
return data;
132+
return node;
132133
}
133134

134135
length() {

0 commit comments

Comments
 (0)