Skip to content

Commit da4edd6

Browse files
👕 refactor: Lint sources.
1 parent 90c3d0d commit da4edd6

File tree

5 files changed

+119
-136
lines changed

5 files changed

+119
-136
lines changed

doc/scripts/header.js

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,31 @@
1-
var domReady = function(callback) {
2-
var state = document.readyState ;
3-
if ( state === 'interactive' || state === 'complete' ) {
4-
callback() ;
5-
}
6-
else {
1+
const domReady = function (callback) {
2+
const state = document.readyState;
3+
if (state === 'interactive' || state === 'complete') {
4+
callback();
5+
} else {
76
document.addEventListener('DOMContentLoaded', callback);
87
}
9-
} ;
10-
8+
};
119

12-
domReady(function(){
13-
14-
var projectname = document.createElement('a');
10+
domReady(function () {
11+
const projectname = document.createElement('a');
1512
projectname.classList.add('project-name');
1613
projectname.text = 'list-abstraction/doubly-linked-list';
17-
projectname.href = './index.html' ;
14+
projectname.href = './index.html';
1815

19-
var header = document.getElementsByTagName('header')[0] ;
20-
header.insertBefore(projectname,header.firstChild);
16+
const header = document.querySelectorAll('header')[0];
17+
header.insertBefore(projectname, header.firstChild);
2118

22-
var testlink = document.querySelector('header > a[data-ice="testLink"]') ;
23-
testlink.href = 'https://coveralls.io/github/list-abstraction/doubly-linked-list' ;
24-
testlink.target = '_BLANK' ;
19+
const testlink = document.querySelector('header > a[data-ice="testLink"]');
20+
testlink.href =
21+
'https://coveralls.io/github/list-abstraction/doubly-linked-list';
22+
testlink.target = '_BLANK';
2523

26-
var searchBox = document.querySelector('.search-box');
27-
var input = document.querySelector('.search-input');
24+
const searchBox = document.querySelector('.search-box');
25+
const input = document.querySelector('.search-input');
2826

29-
// active search box when focus on searchBox.
30-
input.addEventListener('focus', function(){
27+
// Active search box when focus on searchBox.
28+
input.addEventListener('focus', function () {
3129
searchBox.classList.add('active');
3230
});
33-
3431
});

src/DoublyLinkedList.js

Lines changed: 81 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -4,209 +4,197 @@
44
* sake of simplicity.
55
*/
66

7-
export function DoublyLinkedList(){
7+
export function DoublyLinkedList() {
88
this.front = new Node(null, null, null);
99
this.back = new Node(this.front, null, null);
1010
this.front.next = this.back;
1111
this.length = 0;
1212
}
1313

14-
export function Node(prev, next, value){
14+
export function Node(prev, next, value) {
1515
this.prev = prev;
1616
this.next = next;
1717
this.value = value;
1818
}
1919

20-
export function Iterator(front, back, current){
20+
export function Iterator(front, back, current) {
2121
this.front = front;
2222
this.back = back;
2323
this.current = current;
2424
}
2525

26-
export function ReverseIterator(front, back, current){
26+
export function ReverseIterator(front, back, current) {
2727
this.front = front;
2828
this.back = back;
2929
this.current = current;
3030
}
3131

32-
DoublyLinkedList.prototype.insertAfter = function(iterator, value){
33-
var node, prev;
32+
DoublyLinkedList.prototype.insertAfter = function (iterator, value) {
33+
const prev = iterator.current;
3434

35-
prev = iterator.current;
36-
37-
node = new Node(prev, prev.next, value);
35+
const node = new Node(prev, prev.next, value);
3836
prev.next.prev = node;
3937
prev.next = node;
4038

4139
++this.length;
4240
return this.iterator(node);
43-
}
44-
45-
DoublyLinkedList.prototype.insertBefore = function(iterator, value){
46-
var node, next;
41+
};
4742

48-
next = iterator.current;
43+
DoublyLinkedList.prototype.insertBefore = function (iterator, value) {
44+
const next = iterator.current;
4945

50-
node = new Node(next.prev, next, value);
46+
const node = new Node(next.prev, next, value);
5147
next.prev.next = node;
5248
next.prev = node;
5349

5450
++this.length;
5551
return this.iterator(node);
56-
}
52+
};
5753

58-
DoublyLinkedList.prototype.unshift = function(value){
54+
DoublyLinkedList.prototype.unshift = function (value) {
5955
return this.insertAfter(this.begin(), value);
60-
}
56+
};
6157

62-
DoublyLinkedList.prototype.push = function(value){
58+
DoublyLinkedList.prototype.push = function (value) {
6359
return this.insertBefore(this.end(), value);
64-
}
60+
};
6561

66-
DoublyLinkedList.prototype.erase = function(iterator){
67-
var node = iterator.current;
62+
DoublyLinkedList.prototype.erase = function (iterator) {
63+
const node = iterator.current;
6864

6965
node.prev.next = node.next;
7066
node.next.prev = node.prev;
7167

7268
--this.length;
7369
return this.iterator(node.next);
74-
}
70+
};
7571

76-
DoublyLinkedList.prototype.rerase = function(iterator){
77-
var node = iterator.current;
72+
DoublyLinkedList.prototype.rerase = function (iterator) {
73+
const node = iterator.current;
7874

7975
node.next.prev = node.prev;
8076
node.prev.next = node.next;
8177

8278
--this.length;
8379
return this.iterator(node.prev);
84-
}
80+
};
8581

86-
DoublyLinkedList.prototype.eraserange = function(first, last){
87-
var firstnode, lastnode, it;
88-
firstnode = first.current;
89-
lastnode = last.current;
82+
DoublyLinkedList.prototype.eraserange = function (first, last) {
83+
const firstnode = first.current;
84+
const lastnode = last.current;
9085

9186
lastnode.prev = firstnode.prev;
9287
firstnode.prev.next = lastnode;
9388

94-
it = first.copy();
89+
const it = first.copy();
9590

9691
while (it.current !== lastnode) {
9792
--this.length;
9893
it.next();
9994
}
95+
10096
return last.copy();
101-
}
97+
};
10298

103-
DoublyLinkedList.prototype.reraserange = function(first, last){
104-
var firstnode, lastnode, it;
105-
firstnode = first.current;
106-
lastnode = last.current;
99+
DoublyLinkedList.prototype.reraserange = function (first, last) {
100+
const firstnode = first.current;
101+
const lastnode = last.current;
107102

108103
lastnode.next = firstnode.next;
109104
firstnode.next.prev = lastnode;
110105

111-
it = first.copy();
106+
const it = first.copy();
112107

113108
while (it.current !== lastnode) {
114109
--this.length;
115110
it.next();
116111
}
117-
return last.copy();
118-
}
119-
120-
DoublyLinkedList.prototype.shift = function ( ) {
121112

122-
if ( this.length === 0 ) return null ;
123-
124-
const node = this.front.next ;
113+
return last.copy();
114+
};
125115

126-
this.front.next = node.next ;
127-
node.next.prev = this.front ;
116+
DoublyLinkedList.prototype.shift = function () {
117+
if (this.length === 0) return null;
128118

129-
--this.length ;
119+
const node = this.front.next;
130120

131-
return node.value ;
121+
this.front.next = node.next;
122+
node.next.prev = this.front;
132123

133-
}
124+
--this.length;
134125

135-
DoublyLinkedList.prototype.pop = function ( ) {
126+
return node.value;
127+
};
136128

137-
if ( this.length === 0 ) return null ;
129+
DoublyLinkedList.prototype.pop = function () {
130+
if (this.length === 0) return null;
138131

139-
const node = this.back.prev ;
132+
const node = this.back.prev;
140133

141-
this.back.prev = node.prev ;
142-
node.prev.next = this.back ;
134+
this.back.prev = node.prev;
135+
node.prev.next = this.back;
143136

144-
--this.length ;
137+
--this.length;
145138

146-
return node.value ;
139+
return node.value;
140+
};
147141

148-
}
149-
150-
DoublyLinkedList.prototype.clear = function(){
142+
DoublyLinkedList.prototype.clear = function () {
151143
this.front.next = this.back;
152144
this.back.prev = this.front;
153145
this.length = 0;
154146
return this;
155-
}
147+
};
156148

157-
DoublyLinkedList.prototype.iterator = function(node){
149+
DoublyLinkedList.prototype.iterator = function (node) {
158150
return new Iterator(this.front, this.back, node);
159-
}
151+
};
160152

161-
DoublyLinkedList.prototype.riterator = function(node){
153+
DoublyLinkedList.prototype.riterator = function (node) {
162154
return new ReverseIterator(this.front, this.back, node);
163-
}
155+
};
164156

165-
DoublyLinkedList.prototype.begin = function(){
157+
DoublyLinkedList.prototype.begin = function () {
166158
return this.iterator(this.front);
167-
}
159+
};
168160

169-
DoublyLinkedList.prototype.end = function(){
161+
DoublyLinkedList.prototype.end = function () {
170162
return this.iterator(this.back);
171-
}
163+
};
172164

173-
DoublyLinkedList.prototype.rbegin = function(){
165+
DoublyLinkedList.prototype.rbegin = function () {
174166
return this.riterator(this.back);
175-
}
167+
};
176168

177-
DoublyLinkedList.prototype.rend = function(){
169+
DoublyLinkedList.prototype.rend = function () {
178170
return this.riterator(this.front);
179-
}
171+
};
180172

181-
Iterator.prototype.copy = function() {
173+
Iterator.prototype.copy = function () {
182174
return new Iterator(this.front, this.back, this.current);
183-
}
175+
};
184176

185-
ReverseIterator.prototype.copy = function() {
177+
ReverseIterator.prototype.copy = function () {
186178
return new ReverseIterator(this.front, this.back, this.current);
187-
}
188-
189-
Iterator.prototype.next =
190-
ReverseIterator.prototype.prev = function ( ) {
191-
192-
const c = this.current = this.current.next ;
179+
};
193180

194-
return c === this.back ? { done : true } : { value : c.value , done : false } ;
195-
196-
}
181+
// eslint-disable-next-line no-multi-assign
182+
Iterator.prototype.next = ReverseIterator.prototype.prev = function () {
183+
// eslint-disable-next-line no-multi-assign
184+
const c = (this.current = this.current.next);
197185

198-
Iterator.prototype.prev =
199-
ReverseIterator.prototype.next = function ( ) {
186+
return c === this.back ? {done: true} : {value: c.value, done: false};
187+
};
200188

201-
const c = this.current = this.current.prev ;
189+
// eslint-disable-next-line no-multi-assign
190+
Iterator.prototype.prev = ReverseIterator.prototype.next = function () {
191+
// eslint-disable-next-line no-multi-assign
192+
const c = (this.current = this.current.prev);
202193

203-
return c === this.front ? { done : true } : { value : c.value , done : false } ;
194+
return c === this.front ? {done: true} : {value: c.value, done: false};
195+
};
204196

205-
}
206-
207-
DoublyLinkedList.prototype[Symbol.iterator] = DoublyLinkedList.prototype.begin ;
197+
DoublyLinkedList.prototype[Symbol.iterator] = DoublyLinkedList.prototype.begin;
208198
DoublyLinkedList.Node = Node;
209199
DoublyLinkedList.Iterator = Iterator;
210200
DoublyLinkedList.ReverseIterator = ReverseIterator;
211-
212-

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export * from './DoublyLinkedList.js' ;
1+
export * from './DoublyLinkedList.js';

test/src/DoublyLinkedList.js

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,29 @@
11
import test from 'ava';
22
import * as dll from '../../src/index.js';
33

4-
test( "DoublyLinkedList" , t => {
4+
test('DoublyLinkedList', (t) => {
5+
const list = new dll.DoublyLinkedList();
56

6-
const list = new dll.DoublyLinkedList( ) ;
7+
const a = list.push(1);
8+
const b = list.push(2);
9+
const c = list.push(3);
10+
const d = list.push(4);
711

8-
const a = list.push( 1 ) ;
9-
const b = list.push( 2 ) ;
10-
const c = list.push( 3 ) ;
11-
const d = list.push( 4 ) ;
12+
t.is(list.length, 4);
1213

13-
t.deepEqual( list.length , 4 ) ;
14+
t.deepEqual(list.erase(b), c);
1415

15-
t.deepEqual( list.erase( b ) , c ) ;
16+
t.is(list.length, 3);
1617

17-
t.deepEqual( list.length , 3 ) ;
18+
t.deepEqual(list.rerase(c), a);
1819

19-
t.deepEqual( list.rerase( c ) , a ) ;
20+
t.is(list.length, 2);
2021

21-
t.deepEqual( list.length , 2 ) ;
22+
t.deepEqual(list.erase(a), d);
2223

23-
t.deepEqual( list.erase( a ) , d ) ;
24+
t.is(list.length, 1);
2425

25-
t.deepEqual( list.length , 1 ) ;
26+
t.deepEqual(list.erase(d), list.end());
2627

27-
t.deepEqual( list.erase( d ) , list.end( ) ) ;
28-
29-
t.deepEqual( list.length , 0 ) ;
30-
31-
} ) ;
28+
t.is(list.length, 0);
29+
});

0 commit comments

Comments
 (0)