Skip to content

Commit fc815aa

Browse files
✏️ style: Partial linting.
1 parent b9dcef8 commit fc815aa

12 files changed

+680
-811
lines changed

doc/scripts/header.js

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,30 @@
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(() => {
11+
const projectname = document.createElement('a');
1512
projectname.classList.add('project-name');
1613
projectname.text = 'aureooms/js-collections-deque';
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/aureooms/js-collections-deque' ;
24-
testlink.target = '_BLANK' ;
19+
const testlink = document.querySelector('header > a[data-ice="testLink"]');
20+
testlink.href = 'https://coveralls.io/github/aureooms/js-collections-deque';
21+
testlink.target = '_BLANK';
2522

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

29-
// active search box when focus on searchBox.
30-
input.addEventListener('focus', function(){
26+
// Active search box when focus on searchBox.
27+
input.addEventListener('focus', () => {
3128
searchBox.classList.add('active');
3229
});
33-
3430
});

src/_deque.js

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,29 @@
1-
import { TypeError , ValueError } from '@aureooms/js-error' ;
1+
import {TypeError, ValueError} from '@aureooms/js-error';
22

3-
export default function _deque ( UnboundedDeque , BoundedDeque , SingleElementDeque , EmptyDeque ) {
3+
export default function _deque(UnboundedDeque, BoundedDeque, SingleElementDeque, EmptyDeque) {
4+
const deque = function (iterable = null, maxlen = null) {
5+
if (maxlen === null) {
6+
return new UnboundedDeque(iterable);
7+
}
48

5-
const deque = function ( iterable = null , maxlen = null ) {
9+
if (!Number.isInteger(maxlen)) {
10+
throw new TypeError(maxlen);
11+
}
612

7-
if ( maxlen === null ) return new UnboundedDeque( iterable ) ;
13+
if (maxlen === 0) {
14+
return new EmptyDeque(iterable);
15+
}
816

9-
if ( !Number.isInteger( maxlen ) ) throw new TypeError( maxlen ) ;
17+
if (maxlen === 1) {
18+
return new SingleElementDeque(iterable);
19+
}
1020

11-
if ( maxlen === 0 ) return new EmptyDeque( iterable ) ;
21+
if (maxlen > 0) {
22+
return new BoundedDeque(iterable, maxlen);
23+
}
1224

13-
if ( maxlen === 1 ) return new SingleElementDeque( iterable ) ;
14-
15-
if ( maxlen > 0 ) return new BoundedDeque( iterable , maxlen ) ;
16-
17-
throw new ValueError( maxlen ) ;
18-
19-
} ;
20-
21-
return deque ;
25+
throw new ValueError(maxlen);
26+
};
2227

28+
return deque;
2329
}

src/deque.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
import {
2-
Deque ,
3-
ArbitrarySizeDeque ,
4-
UnboundedDeque ,
5-
BoundedDeque ,
6-
SingleElementDeque ,
7-
EmptyDeque ,
8-
} from './implementation' ;
2+
UnboundedDeque,
3+
BoundedDeque,
4+
SingleElementDeque,
5+
EmptyDeque
6+
} from './implementation/index.js';
97

10-
import _deque from './_deque' ;
8+
import _deque from './_deque.js';
119

12-
const deque = _deque( UnboundedDeque , BoundedDeque , SingleElementDeque , EmptyDeque ) ;
10+
const deque = _deque(UnboundedDeque, BoundedDeque, SingleElementDeque, EmptyDeque);
1311

14-
export default deque ;
12+
export default deque;
Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
1-
import Deque from './Deque' ;
1+
import Deque from './Deque.js';
22

3-
export default function ArbitrarySizeDeque ( ) { }
3+
export default function ArbitrarySizeDeque() {}
44

5-
ArbitrarySizeDeque.prototype = new Deque( ) ;
5+
ArbitrarySizeDeque.prototype = new Deque();
66

7-
ArbitrarySizeDeque.prototype.values = function* ( ) {
7+
ArbitrarySizeDeque.prototype.values = function * () {
8+
let i = this.center;
9+
const _m = (i + this.length);
10+
const m = Math.min(this.capacity(), _m);
811

9-
let i = this.center ;
10-
const _m = ( i + this.length ) ;
11-
const m = Math.min( this.capacity( ) , _m ) ;
12+
for (; i < m; ++i) {
13+
yield this.container[i];
14+
}
1215

13-
for ( ; i < m ; ++i ) yield this.container[i] ;
16+
const n = _m % this.capacity();
1417

15-
const n = _m % this.capacity( ) ;
18+
if (n < _m) {
19+
for (i = 0; i < n; ++i) {
20+
yield this.container[i];
21+
}
22+
}
23+
};
1624

17-
if ( n < _m ) for ( i = 0 ; i < n ; ++i ) yield this.container[i] ;
25+
ArbitrarySizeDeque.prototype.pop = function () {
26+
const [container, index] = this._where(this.length - 1);
1827

19-
} ;
28+
return this._popindex(container, index);
29+
};
2030

21-
ArbitrarySizeDeque.prototype.pop = function ( ) {
31+
ArbitrarySizeDeque.prototype.popleft = function () {
32+
const [container, index] = this._where(0);
2233

23-
const [ container , index ] = this._where( this.length - 1 ) ;
34+
++this.center;
35+
this.center %= this.capacity();
2436

25-
return this._popindex( container , index ) ;
26-
27-
} ;
28-
29-
ArbitrarySizeDeque.prototype.popleft = function ( ) {
30-
31-
const [ container , index ] = this._where( 0 ) ;
32-
33-
++this.center ;
34-
this.center %= this.capacity( ) ;
35-
36-
return this._popindex( container , index ) ;
37-
38-
} ;
37+
return this._popindex(container, index);
38+
};

src/implementation/BoundedDeque.js

Lines changed: 60 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,109 +1,86 @@
1-
import ArbitrarySizeDeque from './ArbitrarySizeDeque' ;
1+
import ArbitrarySizeDeque from './ArbitrarySizeDeque.js';
22

3-
export default function BoundedDeque ( iterable , maxlen ) {
3+
export default function BoundedDeque(iterable, maxlen) {
4+
this.maxlen = maxlen;
45

5-
this.maxlen = maxlen ;
6+
// eslint-disable-next-line unicorn/no-new-array
7+
this.container = new Array(maxlen);
68

7-
this.container = new Array( maxlen ) ;
8-
9-
this.center = 0 ;
10-
11-
this.length = 0 ;
12-
13-
if ( iterable !== null ) this.extend( iterable ) ;
9+
this.center = 0;
1410

11+
this.length = 0;
1512

13+
if (iterable !== null) {
14+
this.extend(iterable);
15+
}
1616
}
1717

18-
BoundedDeque.prototype = new ArbitrarySizeDeque( ) ;
19-
20-
BoundedDeque.prototype.len = function ( ) {
21-
22-
return this.length ;
23-
24-
} ;
25-
26-
BoundedDeque.prototype.capacity = function ( ) {
27-
28-
return this.maxlen ;
29-
30-
} ;
31-
32-
BoundedDeque.prototype.append = function ( x ) {
33-
34-
35-
if ( this.length === this.maxlen ) {
36-
37-
this.container[this.center] = x ;
38-
++this.center ;
39-
this.center %= this.maxlen ;
40-
18+
BoundedDeque.prototype = new ArbitrarySizeDeque();
19+
20+
BoundedDeque.prototype.len = function () {
21+
return this.length;
22+
};
23+
24+
BoundedDeque.prototype.capacity = function () {
25+
return this.maxlen;
26+
};
27+
28+
BoundedDeque.prototype.append = function (x) {
29+
if (this.length === this.maxlen) {
30+
this.container[this.center] = x;
31+
++this.center;
32+
this.center %= this.maxlen;
33+
} else {
34+
const i = (this.center + this.length) % this.maxlen;
35+
this.container[i] = x;
36+
++this.length;
4137
}
4238

43-
else {
39+
return this;
40+
};
4441

45-
const i = ( this.center + this.length ) % this.maxlen ;
46-
this.container[i] = x ;
47-
++this.length ;
42+
BoundedDeque.prototype.appendleft = function (x) {
43+
--this.center;
44+
this.center += this.maxlen;
45+
this.center %= this.maxlen;
46+
this.container[this.center] = x;
4847

48+
if (this.length < this.maxlen) {
49+
++this.length;
4950
}
5051

51-
return this ;
52-
53-
} ;
52+
return this;
53+
};
5454

55-
BoundedDeque.prototype.appendleft = function ( x ) {
55+
BoundedDeque.prototype.clear = function () {
56+
this.center = 0;
5657

57-
--this.center ;
58-
this.center += this.maxlen ;
59-
this.center %= this.maxlen ;
60-
this.container[this.center] = x ;
58+
this.length = 0;
6159

62-
if ( this.length < this.maxlen ) ++this.length ;
60+
// eslint-disable-next-line unicorn/no-new-array
61+
this.container = new Array(this.maxlen);
6362

64-
return this ;
63+
return this;
64+
};
6565

66-
} ;
66+
BoundedDeque.prototype.copy = function () {
67+
return new BoundedDeque(this, this.maxlen);
68+
};
6769

68-
BoundedDeque.prototype.clear = function ( ) {
70+
BoundedDeque.prototype._where = function (i) {
71+
this._checkbounds(i);
6972

70-
this.center = 0 ;
73+
return [this.container, (this.center + i) % this.maxlen];
74+
};
7175

72-
this.length = 0 ;
73-
74-
this.container = new Array( this.maxlen ) ;
75-
76-
return this ;
77-
78-
} ;
79-
80-
BoundedDeque.prototype.copy = function ( ) {
81-
82-
return new BoundedDeque( this , this.maxlen ) ;
83-
84-
} ;
85-
86-
87-
88-
BoundedDeque.prototype._where = function ( i ) {
89-
90-
this._checkbounds( i ) ;
91-
92-
return [ this.container , ( this.center + i ) % this.maxlen ] ;
93-
94-
} ;
95-
96-
97-
BoundedDeque.prototype._popindex = function ( container , index ) {
98-
99-
const value = container[index] ;
76+
BoundedDeque.prototype._popindex = function (container, index) {
77+
const value = container[index];
10078

10179
// GC
10280
// TODO use null instead of 0 for non-Number deques
103-
container[index] = 0 ;
104-
105-
--this.length ;
81+
container[index] = 0;
10682

107-
return value ;
83+
--this.length;
10884

109-
} ;
85+
return value;
86+
};

0 commit comments

Comments
 (0)