Skip to content

Commit ccc153a

Browse files
🎨 refactor: Use flat export style.
1 parent f879a5a commit ccc153a

File tree

10 files changed

+39
-46
lines changed

10 files changed

+39
-46
lines changed

src/api/index.js

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/api/randfloat.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,5 @@
33
* according to a uniform distribution.
44
*/
55

6-
export function randfloat(i, j) {
7-
return i + Math.random() * (j - i);
8-
}
6+
const randfloat = (i, j) => i + Math.random() * (j - i);
7+
export default randfloat;

src/api/randint.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,5 @@
33
* according to a uniform distribution.
44
*/
55

6-
export function randint(i, j) {
7-
return i + Math.floor(Math.random() * (j - i));
8-
}
6+
const randint = (i, j) => i + Math.floor(Math.random() * (j - i));
7+
export default randint;

src/api/randrange.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
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) {
7+
const randrange = (start, stop, step) => {
88
// TODO handle empty ranges
99

1010
if (stop === undefined) return randint(0, start);
@@ -15,4 +15,6 @@ export function randrange(start, stop, step) {
1515
}
1616

1717
return start + step * randint(0, Math.floor((start - stop) / -step));
18-
}
18+
};
19+
20+
export default randrange;

src/api/sample.js

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

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

src/api/shuffle.js

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

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

src/index.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
1-
export * from './api/index.js';
2-
export * from './kernel/index.js';
1+
export {default as randfloat} from './api/randfloat.js';
2+
export {default as randint} from './api/randint.js';
3+
export {default as randrange} from './api/randrange.js';
4+
export {default as sample} from './api/sample.js';
5+
export {default as shuffle} from './api/shuffle.js';
6+
export {default as _fisheryates} from './kernel/_fisheryates.js';
7+
export {default as _shuffle} from './kernel/_shuffle.js';

src/kernel/_fisheryates.js

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,22 @@
22
* Sample array using Fisher-Yates method.
33
*/
44

5-
export function _fisheryates(randint) {
6-
const fisheryates = function (n, a, i, j) {
7-
// We will swap at most n elements
5+
const _fisheryates = (randint) => (n, a, i, j) => {
6+
// We will swap at most n elements
87

9-
const k = i + n;
8+
const k = i + n;
109

11-
for (; i < k; ++i) {
12-
// Choose any index p in the remaining array
10+
for (; i < k; ++i) {
11+
// Choose any index p in the remaining array
1312

14-
const p = randint(i, j);
13+
const p = randint(i, j);
1514

16-
// Swap element at index p with first element in the array
15+
// Swap element at index p with first element in the array
1716

18-
const tmp = a[i];
19-
a[i] = a[p];
20-
a[p] = tmp;
21-
}
22-
};
17+
const tmp = a[i];
18+
a[i] = a[p];
19+
a[p] = tmp;
20+
}
21+
};
2322

24-
return fisheryates;
25-
}
23+
export default _fisheryates;

src/kernel/_shuffle.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,5 @@
22
* Shuffle array by sampling the complete array.
33
*/
44

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

src/kernel/index.js

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)