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-

0 commit comments

Comments
 (0)