Skip to content

Commit 0099493

Browse files
👕 refactor: Lint all JavaScript files.
1 parent a8a14f9 commit 0099493

File tree

13 files changed

+830
-800
lines changed

13 files changed

+830
-800
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-persistent';
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-persistent' ;
24-
testlink.target = '_BLANK' ;
19+
const testlink = document.querySelector('header > a[data-ice="testLink"]');
20+
testlink.href = 'https://coveralls.io/github/aureooms/js-persistent';
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
});

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@
190190
"camelcase": "off",
191191
"unicorn/prevent-abbreviations": "off",
192192
"no-constant-condition": "off",
193+
"no-multi-assign": "off",
194+
"unicorn/no-this-assignment": "off",
193195
"unicorn/prefer-math-trunc": "off",
194196
"unicorn/no-new-array": "off",
195197
"no-negated-condition": "off"

src/heap.js

Lines changed: 27 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,36 @@
1+
export function heap(empty, max) {
2+
const Heap = function (tree) {
3+
this.tree = tree;
4+
};
15

2-
export function heap ( empty , max ) {
6+
Heap.prototype.isEmpty = function () {
7+
return this.tree.isEmpty();
8+
};
39

4-
let Heap = function ( tree ) {
5-
this.tree = tree ;
6-
} ;
10+
Heap.prototype.maxKey = Heap.prototype.measure = function () {
11+
return this.tree.measure();
12+
};
713

8-
Heap.prototype.isEmpty = function ( ) {
9-
return this.tree.isEmpty( ) ;
10-
} ;
14+
Heap.prototype.insert = Heap.prototype.push = function (value) {
15+
return new Heap(this.tree.push(value));
16+
};
1117

12-
Heap.prototype.maxKey =
13-
Heap.prototype.measure = function ( ) {
14-
return this.tree.measure( ) ;
15-
} ;
18+
Heap.prototype.extractMax = function () {
19+
const ub = this.measure();
20+
const split = this.tree.splitTree((m) => m >= ub, max.zero());
21+
return [split.middle, new Heap(split.left.concat(split.right))];
22+
};
1623

17-
Heap.prototype.insert =
18-
Heap.prototype.push = function ( value ) {
19-
return new Heap( this.tree.push( value ) ) ;
20-
} ;
24+
Heap.prototype.insertValues = function (values) {
25+
let s = this;
2126

22-
Heap.prototype.extractMax = function ( ) {
23-
const ub = this.measure( ) ;
24-
const split = this.tree.splitTree( ( m ) => m >= ub , max.zero( ) ) ;
25-
return [ split.middle , new Heap( split.left.concat( split.right ) ) ] ;
26-
} ;
27+
for (const value of values) s = s.insert(value);
2728

28-
Heap.prototype.insertValues = function ( values ) {
29-
30-
let s = this ;
31-
32-
for ( const value of values ) s = s.insert( value ) ;
33-
34-
return s ;
35-
36-
} ;
37-
38-
return {
39-
empty : ( ) => new Heap( empty( max ) ) ,
40-
from : ( iterable ) => new Heap( empty( max ) ).insertValues( iterable )
41-
} ;
29+
return s;
30+
};
4231

32+
return {
33+
empty: () => new Heap(empty(max)),
34+
from: (iterable) => new Heap(empty(max)).insertValues(iterable),
35+
};
4336
}

src/index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
export * from "./heap.js" ;
2-
export * from "./indordseq.js" ;
3-
export * from "./intervaltree.js" ;
4-
export * from "./ordseq.js" ;
5-
export * from "./seq.js" ;
1+
export * from './heap.js';
2+
export * from './indordseq.js';
3+
export * from './intervaltree.js';
4+
export * from './ordseq.js';
5+
export * from './seq.js';

src/indordseq.js

Lines changed: 80 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,117 +1,107 @@
1+
export function indordseq(empty, key, size, measure) {
2+
// Probably needs a total order instead of a measure
3+
// this causes generality problems in the insert, merge, partition and delete
4+
// methods
15

2-
export function indordseq ( empty , key , size , measure ) {
6+
const IndOrdSeq = function (tree) {
7+
this.tree = tree;
8+
};
39

4-
// probably needs a total order instead of a measure
5-
// this causes generality problems in the insert, merge, partition and delete
6-
// methods
10+
IndOrdSeq.prototype.isEmpty = function () {
11+
return this.tree.isEmpty();
12+
};
713

8-
const IndOrdSeq = function ( tree ) {
9-
this.tree = tree ;
10-
} ;
14+
IndOrdSeq.prototype.measure = function () {
15+
return this.tree.measure();
16+
};
1117

12-
IndOrdSeq.prototype.isEmpty = function ( ) {
13-
return this.tree.isEmpty( ) ;
14-
} ;
18+
IndOrdSeq.prototype.min = IndOrdSeq.prototype.head = function () {
19+
return this.tree.head();
20+
};
1521

16-
IndOrdSeq.prototype.measure = function ( ) {
17-
return this.tree.measure( ) ;
18-
} ;
22+
IndOrdSeq.prototype.tail = function () {
23+
return new IndOrdSeq(this.tree.tail());
24+
};
1925

20-
IndOrdSeq.prototype.min =
21-
IndOrdSeq.prototype.head = function ( ) {
22-
return this.tree.head( ) ;
23-
} ;
26+
IndOrdSeq.prototype.max = IndOrdSeq.prototype.last = function () {
27+
return this.tree.last();
28+
};
2429

25-
IndOrdSeq.prototype.tail = function ( ) {
26-
return new IndOrdSeq( this.tree.tail( ) ) ;
27-
} ;
30+
IndOrdSeq.prototype.init = function () {
31+
return new IndOrdSeq(this.tree.init());
32+
};
2833

29-
IndOrdSeq.prototype.max =
30-
IndOrdSeq.prototype.last = function ( ) {
31-
return this.tree.last( ) ;
32-
} ;
34+
IndOrdSeq.prototype.takeUntil = function (predicate) {
35+
return new IndOrdSeq(this.tree.takeUntil(predicate));
36+
};
3337

34-
IndOrdSeq.prototype.init = function ( ) {
35-
return new IndOrdSeq( this.tree.init( ) ) ;
36-
} ;
38+
IndOrdSeq.prototype.dropUntil = function (predicate) {
39+
return new IndOrdSeq(this.tree.dropUntil(predicate));
40+
};
3741

38-
IndOrdSeq.prototype.takeUntil = function ( predicate ) {
39-
return new IndOrdSeq( this.tree.takeUntil( predicate ) ) ;
40-
} ;
42+
IndOrdSeq.prototype[Symbol.iterator] = function () {
43+
return this.tree[Symbol.iterator]();
44+
};
4145

42-
IndOrdSeq.prototype.dropUntil = function ( predicate ) {
43-
return new IndOrdSeq( this.tree.dropUntil( predicate ) ) ;
44-
} ;
46+
IndOrdSeq.prototype.split = function (predicate) {
47+
const [left, right] = this.tree.split(predicate);
48+
return [new IndOrdSeq(left), new IndOrdSeq(right)];
49+
};
4550

46-
IndOrdSeq.prototype[Symbol.iterator] = function ( ) {
47-
return this.tree[Symbol.iterator]( ) ;
48-
} ;
51+
IndOrdSeq.prototype.partition = function (value) {
52+
const k = key.measure(value);
53+
return this.split((m) => m[0] >= k);
54+
};
4955

50-
IndOrdSeq.prototype.split = function ( predicate ) {
51-
const [ left , right ] = this.tree.split( predicate ) ;
52-
return [ new IndOrdSeq( left ) , new IndOrdSeq( right ) ] ;
53-
} ;
56+
IndOrdSeq.prototype.insert = function (value) {
57+
const k = key.measure(value);
58+
const [left, right] = this.tree.split((m) => m[0] >= k);
59+
return new IndOrdSeq(left.push(value).concat(right));
60+
};
5461

55-
IndOrdSeq.prototype.partition = function ( value ) {
56-
const k = key.measure( value ) ;
57-
return this.split( m => m[0] >= k ) ;
58-
} ;
62+
IndOrdSeq.prototype.deleteAll = function (value) {
63+
const k = key.measure(value);
64+
const [l, r] = this.tree.split((m) => m[0] >= k);
65+
const [, R] = r.split((m) => m[0] > k);
66+
return new IndOrdSeq(l.concat(R));
67+
};
5968

60-
IndOrdSeq.prototype.insert = function ( value ) {
61-
const k = key.measure( value ) ;
62-
const [ left , right ] = this.tree.split( m => m[0] >= k ) ;
63-
return new IndOrdSeq( left.push( value ).concat( right ) ) ;
64-
} ;
69+
IndOrdSeq.prototype.merge = function (other) {
70+
if (other.isEmpty()) return this;
6571

66-
IndOrdSeq.prototype.deleteAll = function ( value ) {
67-
const k = key.measure( value ) ;
68-
const [ l , r ] = this.tree.split( m => m[0] >= k ) ;
69-
const [ _ , R ] = r.split( m => m[0] > k ) ;
70-
return new IndOrdSeq( l.concat( R ) ) ;
71-
} ;
72+
const a = other.head();
73+
const k = key.measure(a);
7274

73-
IndOrdSeq.prototype.merge = function ( other ) {
75+
const [l, r] = this.split((m) => m[0] > k);
7476

75-
if ( other.isEmpty( ) ) return this ;
77+
return new IndOrdSeq(l.tree.push(a).concat(r.merge(other.tail()).tree));
78+
};
7679

77-
const a = other.head( ) ;
78-
const k = key.measure( a ) ;
80+
IndOrdSeq.prototype.insertValues = function (values) {
81+
let s = this;
7982

80-
const [ l , r ] = this.split( m => m[0] > k ) ;
83+
for (const value of values) s = s.insert(value);
8184

82-
return new IndOrdSeq( l.tree.push( a ).concat( r.merge( other.tail( ) ).tree ) ) ;
85+
return s;
86+
};
8387

84-
} ;
88+
IndOrdSeq.prototype.len = function () {
89+
return this.tree.measure()[1];
90+
};
8591

86-
IndOrdSeq.prototype.insertValues = function ( values ) {
92+
IndOrdSeq.prototype.get = function (index) {
93+
if (index < 0 || index >= this.len())
94+
throw new Error(`wrong index '${index}'`);
8795

88-
let s = this ;
96+
return this.tree.splitTree((m) => m[1] > index, measure.zero()).middle;
97+
};
8998

90-
for ( const value of values ) s = s.insert( value ) ;
91-
92-
return s ;
93-
94-
} ;
95-
96-
IndOrdSeq.prototype.len = function ( ) {
97-
return this.tree.measure( )[1] ;
98-
} ;
99-
100-
IndOrdSeq.prototype.get = function ( index ) {
101-
102-
if ( index < 0 || index >= this.len( ) ) throw new Error( `wrong index '${index}'` ) ;
103-
104-
return this.tree.splitTree( m => m[1] > index , measure.zero( ) ).middle ;
105-
106-
} ;
107-
108-
IndOrdSeq.prototype.splitAt = function ( index ) {
109-
return this.split( m => m[1] > index ) ;
110-
} ;
111-
112-
return {
113-
empty : ( ) => new IndOrdSeq( empty( measure ) ) ,
114-
from : ( iterable ) => new IndOrdSeq( empty( measure ) ).insertValues( iterable )
115-
} ;
99+
IndOrdSeq.prototype.splitAt = function (index) {
100+
return this.split((m) => m[1] > index);
101+
};
116102

103+
return {
104+
empty: () => new IndOrdSeq(empty(measure)),
105+
from: (iterable) => new IndOrdSeq(empty(measure)).insertValues(iterable),
106+
};
117107
}

0 commit comments

Comments
 (0)