Skip to content

Commit f6332b4

Browse files
committed
added DoublyLinkedList class in ES6 syntax
1 parent fef6ca2 commit f6332b4

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

chapter05/03-DoublyLinkedList2.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ let DoublyLinkedList2 = (function () {
2020
tail.set(this, null);
2121
}
2222

23-
append = function (element) {
23+
append(element) {
2424

2525
let node = new Node(element),
2626
current, _tail;
@@ -42,7 +42,7 @@ let DoublyLinkedList2 = (function () {
4242
length.set(this, l);
4343
}
4444

45-
insert = function (position, element) {
45+
insert(position, element) {
4646

4747
//check for out-of-bounds values
4848
if (position >= 0 && position <= this.size()) {
@@ -94,7 +94,7 @@ let DoublyLinkedList2 = (function () {
9494
}
9595
}
9696

97-
removeAt = function (position) {
97+
removeAt(position) {
9898

9999
//check for out-of-bounds values
100100
if (position > -1 && position < this.size()) {
@@ -151,13 +151,13 @@ let DoublyLinkedList2 = (function () {
151151
}
152152
}
153153

154-
remove = function (element) {
154+
remove(element) {
155155

156156
let index = this.indexOf(element);
157157
return this.removeAt(index);
158158
}
159159

160-
indexOf = function (element) {
160+
indexOf(element) {
161161

162162
let current = this.getHead(),
163163
index = -1;
@@ -196,7 +196,7 @@ let DoublyLinkedList2 = (function () {
196196
return length.get(this);
197197
}
198198

199-
toString = function () {
199+
toString() {
200200

201201
let current = this.getHead(),
202202
s = current ? current.element : '';
@@ -209,7 +209,7 @@ let DoublyLinkedList2 = (function () {
209209
return s;
210210
}
211211

212-
inverseToString = function () {
212+
inverseToString() {
213213

214214
let current = this.getTail(),
215215
s = current ? current.element : '';
@@ -222,19 +222,19 @@ let DoublyLinkedList2 = (function () {
222222
return s;
223223
}
224224

225-
print = function () {
225+
print() {
226226
console.log(this.toString());
227227
}
228228

229-
printInverse = function () {
229+
printInverse() {
230230
console.log(this.inverseToString());
231231
}
232232

233233
getHead() {
234234
return head.get(this);
235235
}
236236

237-
getTail = function () {
237+
getTail() {
238238
return tail.get(this);
239239
}
240240
}

0 commit comments

Comments
 (0)