Skip to content

Commit 5ef8dc2

Browse files
👕 refactor: Initial lint.
1 parent d700706 commit 5ef8dc2

File tree

19 files changed

+535
-566
lines changed

19 files changed

+535
-566
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(() => {
11+
const projectname = document.createElement('a');
1512
projectname.classList.add('project-name');
1613
projectname.text = 'heap-data-structure/specification';
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/heap-data-structure/specification' ;
24-
testlink.target = '_BLANK' ;
19+
const testlink = document.querySelector('header > a[data-ice="testLink"]');
20+
testlink.href =
21+
'https://coveralls.io/github/heap-data-structure/specification';
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', () => {
3129
searchBox.classList.add('active');
3230
});
33-
3431
});

src/adt/DummyHeap.js

Lines changed: 35 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,99 +1,75 @@
1+
export function DummyHeap(compare) {
2+
this.compare = function (a, b) {
3+
return compare(a.value, b.value);
4+
};
15

2-
3-
export function DummyHeap ( compare ) {
4-
5-
this.compare = function ( a , b ) { return compare( a.value , b.value ) ; } ;
6-
this.array = [ ] ;
7-
this.length = 0 ;
8-
6+
this.array = [];
7+
this.length = 0;
98
}
109

11-
DummyHeap.Reference = function ( value ) { this.value = value ; } ;
10+
DummyHeap.Reference = function (value) {
11+
this.value = value;
12+
};
1213

1314
DummyHeap.prototype.head = function () {
14-
15-
if ( this.length === 0 ) return undefined;
15+
if (this.length === 0) return undefined;
1616

1717
return this.array[0].value;
18-
1918
};
2019

21-
2220
DummyHeap.prototype.headreference = function () {
23-
24-
if ( this.length === 0 ) return null;
21+
if (this.length === 0) return null;
2522

2623
return this.array[0];
27-
2824
};
2925

30-
3126
DummyHeap.prototype.pop = function () {
27+
if (this.length === 0) return undefined;
3228

33-
if ( this.length === 0 ) return undefined;
34-
35-
--this.length ;
36-
return this.array.shift( ).value ;
37-
29+
--this.length;
30+
return this.array.shift().value;
3831
};
3932

40-
4133
DummyHeap.prototype.popreference = function () {
34+
if (this.length === 0) return null;
4235

43-
if ( this.length === 0 ) return null ;
44-
45-
--this.length ;
46-
return this.array.shift( ) ;
47-
36+
--this.length;
37+
return this.array.shift();
4838
};
4939

40+
DummyHeap.prototype.push = function (value) {
41+
const reference = new DummyHeap.Reference(value);
5042

51-
DummyHeap.prototype.push = function ( value ) {
52-
53-
var reference = new DummyHeap.Reference( value ) ;
54-
55-
this.pushreference( reference ) ;
56-
57-
return reference ;
43+
this.pushreference(reference);
5844

45+
return reference;
5946
};
6047

48+
DummyHeap.prototype.pushreference = function (reference) {
49+
this.array.push(reference);
6150

62-
DummyHeap.prototype.pushreference = function ( reference ) {
63-
64-
this.array.push( reference ) ;
65-
66-
this.array.sort( this.compare ) ;
51+
this.array.sort(this.compare);
6752

6853
++this.length;
69-
7054
};
7155

72-
73-
DummyHeap.prototype.merge = function ( other ) {
74-
75-
this.array = this.array.concat( other.array ).sort( this.compare ) ;
56+
DummyHeap.prototype.merge = function (other) {
57+
this.array = this.array.concat(other.array).sort(this.compare);
7658

7759
this.length += other.length;
78-
79-
} ;
80-
81-
82-
DummyHeap.prototype.update = function ( reference, value ) {
83-
84-
reference.value = value ;
85-
86-
this.array.sort( this.compare ) ;
87-
8860
};
8961

90-
DummyHeap.prototype.decreasekey = DummyHeap.prototype.update ;
62+
DummyHeap.prototype.update = function (reference, value) {
63+
reference.value = value;
9164

92-
DummyHeap.prototype.increasekey = DummyHeap.prototype.update ;
65+
this.array.sort(this.compare);
66+
};
9367

94-
DummyHeap.prototype.delete = function ( reference ) {
68+
DummyHeap.prototype.decreasekey = DummyHeap.prototype.update;
9569

96-
this.array.splice( this.array.indexOf( reference ) , 1 ) ;
97-
--this.length ;
70+
DummyHeap.prototype.increasekey = DummyHeap.prototype.update;
9871

72+
DummyHeap.prototype.delete = function (reference) {
73+
this.array.splice(this.array.indexOf(reference), 1);
74+
--this.length;
9975
};
Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,32 @@
1-
2-
3-
export function DummyHeapWithoutReferences ( compare ) {
4-
5-
this.compare = compare ;
6-
this.array = [ ] ;
7-
this.length = 0 ;
8-
1+
export function DummyHeapWithoutReferences(compare) {
2+
this.compare = compare;
3+
this.array = [];
4+
this.length = 0;
95
}
106

117
DummyHeapWithoutReferences.prototype.head = function () {
12-
13-
if ( this.length === 0 ) return undefined;
8+
if (this.length === 0) return undefined;
149

1510
return this.array[0];
16-
1711
};
1812

19-
20-
2113
DummyHeapWithoutReferences.prototype.pop = function () {
14+
if (this.length === 0) return undefined;
2215

23-
if ( this.length === 0 ) return undefined;
24-
25-
--this.length ;
26-
return this.array.shift( ) ;
27-
16+
--this.length;
17+
return this.array.shift();
2818
};
2919

20+
DummyHeapWithoutReferences.prototype.push = function (value) {
21+
this.array.push(value);
3022

31-
32-
33-
DummyHeapWithoutReferences.prototype.push = function ( value ) {
34-
35-
this.array.push( value ) ;
36-
37-
this.array.sort( this.compare ) ;
23+
this.array.sort(this.compare);
3824

3925
++this.length;
40-
4126
};
4227

43-
44-
DummyHeapWithoutReferences.prototype.merge = function ( other ) {
45-
46-
this.array = this.array.concat( other.array ).sort( this.compare ) ;
28+
DummyHeapWithoutReferences.prototype.merge = function (other) {
29+
this.array = this.array.concat(other.array).sort(this.compare);
4730

4831
this.length += other.length;
49-
50-
} ;
32+
};

src/adt/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
export * from './DummyHeap.js' ;
2-
export * from './DummyHeapWithoutReferences.js' ;
1+
export * from './DummyHeap.js';
2+
export * from './DummyHeapWithoutReferences.js';

src/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export * from './adt/index.js' ;
2-
export * from './parts/index.js' ;
3-
export * from './test.js' ;
4-
export * from './tester.js' ;
1+
export * from './adt/index.js';
2+
export * from './parts/index.js';
3+
export * from './test.js';
4+
export * from './tester.js';

src/parts/decreasekey.js

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,61 @@
1-
import { tester } from '../tester.js' ;
2-
import { shuffle } from '@randomized/random' ;
3-
4-
export function _decreasekey ( _test, length, heapname, Heap, diffname, diff, n ) {
5-
1+
import {shuffle} from '@randomized/random';
2+
import {tester} from '../tester.js';
3+
4+
export function _decreasekey(
5+
_test,
6+
length,
7+
heapname,
8+
makeHeap,
9+
diffname,
10+
diff,
11+
n,
12+
) {
613
const title = `Heap decreasekey (${heapname}, ${diffname}, ${n})`;
714

8-
_test( title, t => {
9-
10-
const q = Heap( diff );
15+
_test(title, (t) => {
16+
const q = makeHeap(diff);
1117
const pairs = [];
1218
const b = [];
1319

14-
if (length) t.deepEqual( q.length, 0, "check length zero" );
20+
if (length) t.deepEqual(q.length, 0, 'check length zero');
1521

1622
let i = n;
17-
while ( i-- ) {
23+
while (i--) {
1824
const x = Math.random();
19-
const reference = q.push( x );
20-
pairs.push( { ref: reference, value: x} );
21-
if (length) t.deepEqual( q.length, pairs.length);
25+
const reference = q.push(x);
26+
pairs.push({ref: reference, value: x});
27+
if (length) t.deepEqual(q.length, pairs.length);
2228
}
2329

24-
shuffle( pairs, 0, n );
30+
shuffle(pairs, 0, n);
2531

2632
const order = diffname === 'increasing' ? 1 : -1;
2733

28-
for ( i = 0 ; i < n ; ++i ) {
29-
34+
for (i = 0; i < n; ++i) {
3035
pairs[i].value -= Math.random() * order;
31-
q.decreasekey( pairs[i].ref, pairs[i].value );
32-
if (length) t.deepEqual( q.length, n );
33-
36+
q.decreasekey(pairs[i].ref, pairs[i].value);
37+
if (length) t.deepEqual(q.length, n);
3438
}
3539

3640
i = n;
3741

38-
while ( i-- ) {
39-
40-
b.push( q.pop() );
41-
if (length) t.deepEqual( q.length, i );
42-
42+
while (i--) {
43+
b.push(q.pop());
44+
if (length) t.deepEqual(q.length, i);
4345
}
4446

45-
const a = pairs.map(x => x.value);
46-
a.sort( diff );
47+
const a = pairs.map((x) => x.value);
48+
a.sort(diff);
4749

48-
t.deepEqual( b, a, "check identical" );
50+
t.deepEqual(b, a, 'check identical');
4951

50-
if (length) t.deepEqual( q.length, 0, "check length zero" );
51-
52-
t.deepEqual( q.head(), undefined, "check head empty" );
53-
t.deepEqual( q.headreference(), null, "check headreference empty" );
54-
t.deepEqual( q.pop(), undefined, "check pop empty" );
55-
t.deepEqual( q.popreference(), null, "check popreference empty" );
52+
if (length) t.deepEqual(q.length, 0, 'check length zero');
5653

54+
t.deepEqual(q.head(), undefined, 'check head empty');
55+
t.deepEqual(q.headreference(), null, 'check headreference empty');
56+
t.deepEqual(q.pop(), undefined, 'check pop empty');
57+
t.deepEqual(q.popreference(), null, 'check popreference empty');
5758
});
58-
5959
}
6060

61-
export const decreasekey = tester( _decreasekey ) ;
61+
export const decreasekey = tester(_decreasekey);

0 commit comments

Comments
 (0)