Skip to content

Commit 29f3507

Browse files
🎨 style: Lint with xo.
1 parent a376c74 commit 29f3507

File tree

5 files changed

+1781
-120
lines changed

5 files changed

+1781
-120
lines changed

package.json

+14-3
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@
100100
"np": "6.5.0",
101101
"nyc": "15.1.0",
102102
"power-assert": "1.6.1",
103-
"regenerator-runtime": "0.13.7"
103+
"regenerator-runtime": "0.13.7",
104+
"xo": "^0.33.1"
104105
},
105106
"files": [
106107
"lib"
@@ -125,11 +126,21 @@
125126
"cover": "nyc --reporter=lcov npm test",
126127
"dev": "npm run lint -- --fix && npm run cover -- -- -st --fail-fast",
127128
"esdoc": "esdoc",
128-
"lint": "true",
129+
"lint": "xo",
129130
"prepare": "npm run build",
130131
"release": "np",
131132
"test": "ava",
132133
"travis": "npm run lint && npm run cover"
133134
},
134-
"sideEffects": false
135+
"sideEffects": false,
136+
"xo": {
137+
"prettier": true,
138+
"ignore": [
139+
"lib",
140+
"doc"
141+
],
142+
"plugins": [
143+
"unicorn"
144+
]
145+
}
135146
}

src/fordjohnson.js

+43-62
Original file line numberDiff line numberDiff line change
@@ -1,93 +1,74 @@
1+
export default function fordjohnson(binarysearch) {
2+
const sort = function (compare, swap, a, i, j) {
3+
if (j - i < 2) return;
14

2-
export default function fordjohnson ( binarysearch ) {
5+
const m = ((j - i) / 2) | 0;
6+
let k = m;
37

4-
const sort = function ( compare , swap , a , i , j ) {
5-
6-
var m , k , t , y , p , q , r , x , l , w , s , pairswap ;
7-
8-
if ( j - i < 2 ) return ;
9-
10-
k = m = ( j - i ) / 2 | 0 ;
11-
12-
// compare pairs of elements and put largest elements at the front of the
8+
// Compare pairs of elements and put largest elements at the front of the
139
// array
1410

15-
while ( k-- ) {
16-
17-
if ( compare( a[i+k] , a[i+m+k] ) < 0 ) {
18-
19-
swap( a , i + k , i + m + k ) ;
20-
11+
while (k--) {
12+
if (compare(a[i + k], a[i + m + k]) < 0) {
13+
swap(a, i + k, i + m + k);
2114
}
22-
2315
}
2416

25-
// sort the largest elements at the front recursively
26-
27-
pairswap = function ( a , i , j ) {
28-
swap( a , i , j ) ;
29-
swap( a , i + m , j + m ) ;
30-
} ;
31-
32-
sort( compare , pairswap , a , i , i + m ) ;
33-
34-
// merge the rest of the array into the front, one item at a time
17+
// Sort the largest elements at the front recursively
3518

36-
p = y = t = 1 ;
19+
const pairswap = function (a, i, j) {
20+
swap(a, i, j);
21+
swap(a, i + m, j + m);
22+
};
3723

38-
q = 0 ;
24+
sort(compare, pairswap, a, i, i + m);
3925

40-
while ( i + m + t <= j ) {
26+
// Merge the rest of the array into the front, one item at a time
4127

42-
r = t ;
28+
let p = 1;
29+
let y = 1;
30+
let t = 1;
4331

44-
while ( r --> q ) {
32+
let q = 0;
4533

46-
w = a[i+m+t-1] ;
34+
while (i + m + t <= j) {
35+
let r = t;
4736

48-
x = binarysearch( compare , a , i , i + m + q , w ) ;
49-
l = x[0] + x[1] ;
37+
while (r-- > q) {
38+
const w = a[i + m + t - 1];
5039

51-
s = i + m + t ;
40+
const x = binarysearch(compare, a, i, i + m + q, w);
41+
const l = x[0] + x[1];
5242

53-
while ( --s > l ) {
54-
55-
swap( a , s , s - 1 ) ;
43+
let s = i + m + t;
5644

45+
while (--s > l) {
46+
swap(a, s, s - 1);
5747
}
58-
5948
}
6049

61-
q = t ;
62-
63-
p *= 2 ;
64-
y = p - 2 * t ;
65-
t += y ;
50+
q = t;
6651

52+
p *= 2;
53+
y = p - 2 * t;
54+
t += y;
6755
}
6856

69-
r = j - i - m ;
70-
71-
while ( r --> q ) {
72-
73-
w = a[j-1] ;
57+
let r = j - i - m;
7458

75-
x = binarysearch( compare , a , i , i + m + q , w ) ;
76-
l = x[0] + x[1] ;
59+
while (r-- > q) {
60+
const w = a[j - 1];
7761

78-
s = j ;
62+
const x = binarysearch(compare, a, i, i + m + q, w);
63+
const l = x[0] + x[1];
7964

80-
while ( --s > l ) {
81-
82-
swap( a , s , s - 1 ) ;
65+
let s = j;
8366

67+
while (--s > l) {
68+
swap(a, s, s - 1);
8469
}
85-
86-
8770
}
71+
};
8872

89-
} ;
90-
91-
return sort ;
92-
73+
return sort;
9374
}

src/index.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
import fordjohnson from './fordjohnson' ;
1+
import fordjohnson from './fordjohnson';
22

33
/* eslint import/no-anonymous-default-export: [2, {"allowObject": true}] */
44
export default {
5-
fordjohnson ,
6-
} ;
5+
fordjohnson
6+
};
77

8-
export {
9-
fordjohnson ,
10-
} ;
8+
export {fordjohnson};

test/src/spec.js

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
import ava from 'ava' ;
1+
// eslint-disable-next-line ava/use-test
2+
import ava from 'ava';
23

3-
import * as spec from "@aureooms/js-in-situ-sort-spec" ;
4+
import * as spec from '@aureooms/js-in-situ-sort-spec';
45

5-
import { swap } from "@aureooms/js-array" ;
6-
import { binarysearch } from "@aureooms/js-search" ;
7-
import {fordjohnson} from "../../src" ;
6+
import {swap} from '@aureooms/js-array';
7+
import {binarysearch} from '@aureooms/js-search';
8+
import {fordjohnson} from '../../src';
89

9-
const fj = fordjohnson( binarysearch ) ;
10-
const sort = (compare, a, i, j) => fj(compare, swap, a, i, j) ;
10+
const fj = fordjohnson(binarysearch);
11+
const sort = (compare, a, i, j) => fj(compare, swap, a, i, j);
1112

12-
spec.test( ava , [ [ "fordjohnson" , sort ] ] ) ;
13+
spec.test(ava, [['fordjohnson', sort]]);

0 commit comments

Comments
 (0)