Skip to content

Commit cd4fa47

Browse files
👕 refactor: Lint all JavaScript sources.
1 parent 9ba995c commit cd4fa47

19 files changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
export * from "./randfloat.js" ;
2-
export * from "./randint.js" ;
3-
export * from "./randrange.js" ;
4-
export * from "./sample.js" ;
5-
export * from "./shuffle.js" ;
1+
export * from './randfloat.js';
2+
export * from './randint.js';
3+
export * from './randrange.js';
4+
export * from './sample.js';
5+
export * from './shuffle.js';

src/api/randfloat.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
21
/**
32
* Returns a floating point number in interval [i, j[ (i included, j excluded)
43
* according to a uniform distribution.
54
*/
65

7-
export function randfloat ( i , j ) {
8-
return i + Math.random( ) * ( j - i ) ;
6+
export function randfloat(i, j) {
7+
return i + Math.random() * (j - i);
98
}
10-

src/api/randint.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
21
/**
32
* Returns an integer in interval [i, j[ (i included, j excluded)
43
* according to a uniform distribution.
54
*/
65

7-
export function randint ( i , j ) {
8-
return i + Math.floor( Math.random( ) * ( j - i ) ) ;
6+
export function randint(i, j) {
7+
return i + Math.floor(Math.random() * (j - i));
98
}
10-

src/api/randrange.js

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
1-
import { randint } from "./randint.js" ;
1+
import {randint} from './randint.js';
22

33
/**
44
* Return a randomly selected element from range(start, stop, step).
55
*/
66

7-
export function randrange ( start , stop , step ) {
8-
7+
export function randrange(start, stop, step) {
98
// TODO handle empty ranges
109

11-
if ( stop === undefined ) return randint( 0 , start ) ;
12-
if ( step === undefined ) step = 1 ;
10+
if (stop === undefined) return randint(0, start);
11+
if (step === undefined) step = 1;
1312

14-
if ( stop >= start ) {
15-
return start + step * randint( 0 , Math.floor( ( stop - start ) / step ) ) ;
16-
}
17-
else {
18-
return start + step * randint( 0 , Math.floor( ( start - stop ) / -step ) ) ;
13+
if (stop >= start) {
14+
return start + step * randint(0, Math.floor((stop - start) / step));
1915
}
2016

17+
return start + step * randint(0, Math.floor((start - stop) / -step));
2118
}
22-

src/api/sample.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { _fisheryates } from "../kernel/index.js" ;
2-
import { randint } from "./randint.js" ;
1+
import {_fisheryates} from '../kernel/index.js';
2+
import {randint} from './randint.js';
33

4-
export const sample = _fisheryates( randint ) ;
4+
export const sample = _fisheryates(randint);

src/api/shuffle.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { _shuffle } from "../kernel/index.js" ;
2-
import { sample } from "./sample.js" ;
1+
import {_shuffle} from '../kernel/index.js';
2+
import {sample} from './sample.js';
33

4-
export const shuffle = _shuffle( sample ) ;
4+
export const shuffle = _shuffle(sample);

src/index.js

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

src/kernel/_fisheryates.js

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,25 @@
1-
21
/**
32
* Sample array using Fisher-Yates method.
43
*/
54

6-
export function _fisheryates ( randint ) {
7-
8-
const fisheryates = function ( n , a , i , j ) {
9-
10-
// we will swap at most n elements
11-
12-
const k = i + n ;
13-
14-
for ( ; i < k ; ++i ) {
5+
export function _fisheryates(randint) {
6+
const fisheryates = function (n, a, i, j) {
7+
// We will swap at most n elements
158

16-
// choose any index p in the remaining array
9+
const k = i + n;
1710

18-
const p = randint( i , j ) ;
11+
for (; i < k; ++i) {
12+
// Choose any index p in the remaining array
1913

14+
const p = randint(i, j);
2015

21-
// swap element at index p with first element in the array
22-
23-
const tmp = a[i] ;
24-
a[i] = a[p] ;
25-
a[p] = tmp ;
16+
// Swap element at index p with first element in the array
2617

18+
const tmp = a[i];
19+
a[i] = a[p];
20+
a[p] = tmp;
2721
}
22+
};
2823

29-
} ;
30-
31-
return fisheryates ;
32-
24+
return fisheryates;
3325
}
34-

src/kernel/_shuffle.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
1-
21
/**
32
* Shuffle array by sampling the complete array.
43
*/
54

6-
export function _shuffle ( sample ) {
7-
8-
const shuffle = function ( a , i , j ) {
9-
sample( j - i , a , i , j ) ;
10-
} ;
11-
12-
return shuffle ;
5+
export function _shuffle(sample) {
6+
const shuffle = function (a, i, j) {
7+
sample(j - i, a, i, j);
8+
};
139

10+
return shuffle;
1411
}
15-

src/kernel/index.js

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

test/src/randfloat.js

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,43 @@
11
import test from 'ava';
2-
import * as random from "../../src/index.js";
2+
import {randfloat} from '../../src/index.js';
33

4+
import type from '@aureooms/js-type';
45

5-
import util from "util" ;
6+
test('randfloat', (t) => {
7+
let r;
68

7-
import type from "@aureooms/js-type" ;
9+
const n = 5000;
10+
let ri = -n;
11+
let rj = n;
812

9-
10-
11-
test( "randfloat", t => {
12-
13-
var i, n, r, ri, rj, check;
14-
15-
n = 5000;
16-
ri = -n;
17-
rj = n;
18-
19-
check = function () {
20-
t.truthy( r < rj, util.format( "%s < %s", r, rj ) );
21-
t.truthy( r >= ri, util.format( "%s >= %s", r, ri ) );
22-
t.truthy( type.isfinite(r), util.format( "type.isint(%s)", r ) );
13+
const check = () => {
14+
t.true(r < rj, `${r} < ${rj}`);
15+
t.true(r >= ri, `${r} >= ${ri}`);
16+
t.true(type.isfinite(r), `type.isfinite(${r})`);
2317
};
2418

25-
for ( i = 0 ; i < n ; ++i ) {
26-
r = random.randfloat( ri, rj );
19+
for (let i = 0; i < n; ++i) {
20+
r = randfloat(ri, rj);
2721

2822
check();
2923

3024
++ri;
3125
}
3226

33-
for ( i = 0 ; i < n ; ++i ) {
34-
r = random.randfloat( ri, rj );
27+
for (let i = 0; i < n; ++i) {
28+
r = randfloat(ri, rj);
3529

3630
check();
3731

3832
--ri;
3933
--rj;
4034
}
4135

42-
for ( i = 0 ; i < n ; ++i ) {
43-
r = random.randfloat( ri, rj );
36+
for (let i = 0; i < n; ++i) {
37+
r = randfloat(ri, rj);
4438

4539
check();
4640

4741
++rj;
4842
}
49-
50-
5143
});

test/src/randint.js

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,43 @@
11
import test from 'ava';
2-
import * as random from "../../src/index.js";
2+
import {randint} from '../../src/index.js';
33

4+
import type from '@aureooms/js-type';
45

5-
import util from "util" ;
6+
test('randint', (t) => {
7+
let r;
68

7-
import type from "@aureooms/js-type" ;
9+
const n = 5000;
10+
let ri = -n;
11+
let rj = n;
812

9-
10-
11-
test( "randint", t => {
12-
13-
var i, n, r, ri, rj, check;
14-
15-
n = 5000;
16-
ri = -n;
17-
rj = n;
18-
19-
check = function () {
20-
t.truthy( r < rj, util.format( "%s < %s", r, rj ) );
21-
t.truthy( r >= ri, util.format( "%s >= %s", r, ri ) );
22-
t.truthy( type.isint(r), util.format( "type.isint(%s)", r ) );
13+
const check = () => {
14+
t.true(r < rj, `${r} < ${rj}`);
15+
t.true(r >= ri, `${r} >= ${ri}`);
16+
t.true(type.isint(r), `type.isint(${r})`);
2317
};
2418

25-
for ( i = 0 ; i < n ; ++i ) {
26-
r = random.randint( ri, rj );
19+
for (let i = 0; i < n; ++i) {
20+
r = randint(ri, rj);
2721

2822
check();
2923

3024
++ri;
3125
}
3226

33-
for ( i = 0 ; i < n ; ++i ) {
34-
r = random.randint( ri, rj );
27+
for (let i = 0; i < n; ++i) {
28+
r = randint(ri, rj);
3529

3630
check();
3731

3832
--ri;
3933
--rj;
4034
}
4135

42-
for ( i = 0 ; i < n ; ++i ) {
43-
r = random.randint( ri, rj );
36+
for (let i = 0; i < n; ++i) {
37+
r = randint(ri, rj);
4438

4539
check();
4640

4741
++rj;
4842
}
49-
50-
5143
});

0 commit comments

Comments
 (0)